Git Product home page Git Product logo

nifty_services's Introduction

NiftyServices

Build Status

Gem Version


Introduction

Nifty Services comes to solve your Ruby applications(including but not limited to Rails, Grape, Sinatra, and plain Ruby) code mess with simplicity in mind!

NiftyServices provides a very nifty, simple & clear API to organize and reuse your application domain logic in plain Ruby Services Objects turning your codebase in a very extensible, standardized and reusable components.

Most important: You and your team win what I consider the best benefit when using Nifty Services: Easily and scalable maintained code. Believe me, you'll fall in ๐Ÿ˜ with this small piece of code, keep reading!

This gem was designed and conventioned to be used specially with Web API applications, but this is just a convention, you can use it even with shoes (for desktop apps) applications if you want, for example.

๐Ÿ“– I know, this README is very huge

As you can see, this README needs some time to be full read, but is very difficulty to explain all things, concepts and philosophy of this gem without writing a lot, we can't escape this :(

But remember one thing: This is a tecnical documentation, not a blog post, I'm pretty sure you can take about 30 minutes + some cups of โ˜• to better understand all NiftyServices can do for you and your project. Good reading, and if you have some question, please let me know.

Update: Now the documentation was separated in Wiki format. So it's a lot easier for reading.


Conventions

Below, some very importants things about conventions for this cute ๐Ÿ’Ž :)

โœ… Single responsibility

Each service class is responsible for perform exactly one single task, say goodbye for code (most important: logic) duplication in your code. Beside this, one of the aim of NiftyServices is to provide a very standardized code architecture, allowing developers to quickly develop and implement new features keeping the application codebase organized and stable.

๐Ÿ”จ Common and single-run execution method

Each service object must respond to #execute instance method, which is allowed to be called just one time per instance. #execute method is responsible to perform code validation(parameter validation, access level control), execution(send mail, register users) and fire callbacks so you can execute hooks actions after/before success or execution fail.

๐Ÿ“ฆ Rich Service Objects

When dealing with services objects, you will get a very rich objects to work with, forgot about getting only true or false return values, one of the main purpose of objects it's to keep your code domain logic accessible and reusable, so your application can really take the best approach when responding to actions.

๐Ÿ”’ Security - Access Control Level

Think and implement security rules from the first minutes of live in your applications! NiftyServices strongly rely on Access Control Level(ACL) to perform actions, in other words, you will only allow authorized users to read, create, update or delete records in your database!

Now you know the basic concepts and philosophy of NiftyServices, lets start working with this candy library?


Table of Contents


Installation

Add this line to your application's Gemfile:

gem 'nifty_services', '~> 0.0.5'

And then execute:

$ bundle

Or install it yourself as:

$ gem install nifty_services

๐Ÿ“† Roadmap

  • โ—ฝ Create CLI Generators
  • โ—ฝ Beter documentation for BaseActionService
  • โ—ฝ Write Sample Applications
  • โ—ฝ Write better tests for all Crud Services
  • โ—ฝ Write better tests for BaseActionServices
  • โ—ฝ Write tests for Configuration
  • โ—ฝ Write tests for Callbacks

๐Ÿ’ป Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake rspec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem(:gem:) onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.


๐Ÿ‘ Contributing

Bug reports and pull requests are welcome on GitHub at http://github.com/fidelisrafael/nifty_services. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.


๐Ÿ“ License

The gem is available as open source under the terms of the MIT License.

nifty_services's People

Contributors

fidelisrafael avatar lucasgomide avatar viniciuszago avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

nifty_services's Issues

Invalid user should respond with 422 instead of 404

As I see here, it should be an unprocessable_entity error instead of not_found, because it is a create action and doesn't make sense to check if user is not found to create it.

https://github.com/fidelisrafael/nifty_services#alien-invalid-user-

You must have the following keys setup up in your locales files:

 nifty_services:
   users:
     not_found: "Invalid or not found user"
     ip_temporarily_blocked: "This IP is temporarily blocked from creating records"
   # note: posts is the key return in `record_error_key` service method
   posts:
      user_cant_create: "User cant create this record"

๐Ÿ‘ฝ Invalid user

If you try to create a post for a invalid user, such as:

# PostCreateService.new(user, options)
service = PostCreateService.new(nil, options)
service.execute

service.success? # false
service.response_status # :not_found
service.response_status_code # 404
service.errors # ["Invalid or not found user"]

Move this README into Wiki Pages

Hi Fidelis,

I spent some time reading all documentation and I think it is confuse sometimes, because there is too much information on the same page and I need to keep scrolling to find something I have read.

What do you think to move everything to Wiki pages and just let the summary on README?

WHITELIST_ATTRIBUTES could be Class Method

I was thinking that constant WHITELIST_ATTRIBUTES could be a Class Method like record_type
For example, Instead of:

WHITELIST_ATTRIBUTES = [:title, :content]

def record_allowed_attributes
   WHITELIST_ATTRIBUTES
  end

Could be:

whitelist_attributes :title, :content

What do you think?

Generic response methods for services

Should you create this helper method in a generic helper which could be accessed from anywhere?

def generic_response_for_service(service, success_response)
    default_response = {
      status: service.response_status,
      status_code: service.response_status_code,
      success: service.success?
    }

    if service.success?
      response = success_response
    else
      response = {
        error: true,
        errors: service.errors
      }
    end

    default_response.merge(response)
  end

I like the idea of have this method in BaseController, so I can use from every controller by ihneritance, what do you think?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.