README.md in command_service_object-0.6.5 vs README.md in command_service_object-1.0.0

- old
+ new

@@ -6,15 +6,19 @@ [Command Design Pattern](https://en.wikipedia.org/wiki/Command_pattern) consists of `Command Object` and `Service Object` (Executor), Command object is responsible for containing `Client` requests and run input validations on it to ensure that the request is valid and set default values, then `Service Object` applies the business logic on that command. ### Implementation -Service consists of several objects { `Command Object` `Usecase Object` And `Error Object` (business logic error) }. +Service consists of several objects { `Command Object` `Usecase Object` And `Error Object` (business logic error) }. -- **Command Object:** the object that responsible for containing `Client` requests and run input validations it's implemented using [Virtus](https://github.com/solnic/virtus) gem and can use `activerecord` for validations and it's existed under `commands` dir. -- **Usecase Object:** this object responsible for executing the business logic, Every `usecase` should execute one command type only so that command name should be the same as usecase object name, usecase object existed under 'usecases` dir. -- **Micros:** small reusable logic under the same service. +- **[Command](https://en.wikipedia.org/wiki/Command_pattern):** the object that responsible for containing `Client` requests and run input validations it's implemented using [Virtus](https://github.com/solnic/virtus) gem and can use `activerecord` for validations and it's existed under `commands` dir. +- **Usecase:** this object responsible for executing the business logic, Every `usecase` should execute one command type only so that command name should be the same as usecase object name, usecase object existed under 'usecases` dir. +- **Micros:** Small reusable logic under the same service. +- **Externals:** Simple ruby module works as a service interface whenever you wanna call any external service or even service that lives under the same project you should use it. +- **Queries:** This dir is the only entry point for you to get any data form a service. +- **Listeners:** An event listener that waits for an event outside the service to occur. +- **Entities:** Many objects are not fundamentally defined by their attributes, but rather by a thread of continuity and identity. #### Result Object In case of successful or failure `ApplicationService` the responsible object for all services will return `service_result` object this object contain `value!` method containing successful call result, and `errors` method containing failure `errors` objects. @@ -54,12 +58,12 @@ output ```bash app/services/ ├── application_service.rb -├── external/ ├── auth_service +│ ├ external/ │   ├── commands │   │   └── login.rb │   └── usecases │   ├── login.rb │   └── micros @@ -97,15 +101,13 @@ ```ruby # app/services/auth_service/commands/login.rb # frozen_string_literal: true module AuthService::Commands - class Login + class Login < CommandBase # You can read Virtus gem doc for more info. # https://github.com/solnic/virtus - include Virtus.model - include ActiveModel::Validations # Attributes # attribute :REPLACE_ME, String # Validations @@ -127,18 +129,34 @@ # # Your business logic goes here, keep [call] method clean by using private # methods for Business logic. # def call - token = generate_jwt_token_for(user) + token = generate_jwt_token_for(cmd.user) + replace_me + + output end + def output + # return entity object + end + # This method will run if call method raise error def rollback # rollback logic end + + def allowed? + # policies loginc for issuer + # ex: + # + # return false if issuer.role != :admin + true + end + private def replace_me # [business logic] end @@ -152,19 +170,19 @@ #### ex ```ruby module External - class StripeService - class << self - def charge(customer:, amount:, currency:, description: nil) - Stripe::Charge.create( - customer: customer.id, - amount: (round_up(amount, currency) * 100).to_i, - description: description || customer.email, - currency: currency - ) - end + module StripeService + extend self + + def charge(customer:, amount:, currency:, description: nil) + Stripe::Charge.create( + customer: customer.id, + amount: (round_up(amount, currency) * 100).to_i, + description: description || customer.email, + currency: currency + ) end end end ```