Module: ActionSprout::MethodObject

Defined in:
lib/action_sprout/method_object.rb,
lib/action_sprout/method_object/railtie.rb,
lib/action_sprout/method_object/version.rb

Overview

MethodObject is a quick shortcut for creating “method objects”. Under the hood, it uses kwattr. Check out the [kwattr docs][] for how to configure options.

[kwattr docs]: github.com/etiennebarrie/kwattr

Example:

class SaveUser
  method_object :user, repository: UserRepository.new

  def call
    repository.save user
  end
end

SaveUser.call user: user

Summary of kwattr options:

kwattr stands for key-word-attributes and therefore only supports setting up method objects that take keyword arguments. Each positional argument passed to method_object represents a required attribute, and each keyword argument passed to method_object represents an option attribute and its default.

Defined Under Namespace

Modules: ClassMethods Classes: Railtie

Constant Summary collapse

VERSION =
"0.2.0"

Instance Method Summary collapse

Instance Method Details

#method_object(*args) ⇒ Object



31
32
33
34
# File 'lib/action_sprout/method_object.rb', line 31

def method_object(*args)
  extend ClassMethods
  kwattr(*args)
end