Giter Club home page Giter Club logo

smart_operation's Introduction

SmartCore::Operation · Supported by Cado Labs · Gem Version

Smart implementation of the most-used programming pattern - Service Object. Powered by smart_injection, smart_container, smart_types and smart_initializer.

previous generation: https://github.com/0exp/smart_core


Supported by Cado Labs


Main features


Installation

gem 'smart_operation'
bundle install
# --- or ---
gem install smart_types
require 'smart_core/operation'

Synopsis

class CreateUser < SmartCore::Operation
  register_container(ReposContainer)

  import({ user_repo: 'business.users' }, access: :private)

  option :name, 'value.string'
  option :password, 'value.string'
  option :age, 'value.integer'

  def call
    user = user_repo.create({ name: name, password: password, age: age })
    Success(user: user) # or Callback { puts 'wow o.O' }
  end
end

CreateUser.call(name: 'Rustam', password: 'test123', age: 28) do |result|
  result.success?  { puts 'success!' }
  result.failure?  { puts 'failure!' }
  result.fatal?    { puts 'fatal!' }
  result.callback? { result.call } # or some_object.instance_eval(&result.callback)
end # NOTE: returns <result> object, but invokes the correspinding block

# COMING SOON:
CreateUser.exec(name: 'Rustam', password: 'test123', age: 28) do |result|
  # ...the same code as above...
end # NOTE: returns the result of the corresponding invoked block object

Pre-requisits:

class UserRepo
  def create(user_creds)
     # ... some code
  end
end

ReposContainer = SmartCore::Container.define do
  namespace(:business) do
    register(:users) { UserRepo.new }
  end
end

Roadmap

  • method memoization logic (with abilities to refresh memoized methods);
  • pattern matching for result objects (Success, Failure, Fatal, Callback);
  • migrate to Github Actions;
  • parametrized .call methods (ServiceObject.with(attrs_a).call(attrs_b) => ServiceObject.new(attrs_b).call(attrs_a) or something another);
  • think about default exception classes and interfaces to support a basic domain-specific exception class definitioning (common practice);
  • generators: an ability to invoke result block in repeatable yield-like style 🤔 (think about Fibers, js-like generators and similar) (for example: .generator(call_attrs) do |result| # repeatable result block invokation for each "yield" from an inside "generator" method);

Build

  • run tests:
bundle exec rspec
  • run code style checks:
bundle exec rubocop
  • run code style checks with auto-correction:
bundle exec rubocop -A

Contributing

  • Fork it ( https://github.com/smart-rb/smart_operation )
  • Create your feature branch (git checkout -b feature/my-new-feature)
  • Commit your changes (git commit -am '[feature_context] Add some feature')
  • Push to the branch (git push origin feature/my-new-feature)
  • Create new Pull Request

License

Released under MIT License.

Supporting

Supported by Cado Labs

Authors

Rustam Ibragimov

smart_operation's People

Contributors

0exp 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

Forkers

nj0308

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.