Class: Upmin::Action
- Inherits:
-
Object
- Object
- Upmin::Action
- Includes:
- AutomaticDelegation
- Defined in:
- lib/upmin/action.rb
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(model, action_name, options = {}) ⇒ Action
constructor
A new instance of Action.
- #parameters ⇒ Object (also: #arguments)
- #path ⇒ Object
- #perform(arguments) ⇒ Object
- #title ⇒ Object
Methods included from AutomaticDelegation
#delegatable?, #delegated?, #method, #method_missing, #respond_to?
Constructor Details
#initialize(model, action_name, options = {}) ⇒ Action
Returns a new instance of Action.
8 9 10 11 |
# File 'lib/upmin/action.rb', line 8 def initialize(model, action_name, = {}) @model = model @name = action_name.to_sym end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Upmin::AutomaticDelegation
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
5 6 7 |
# File 'lib/upmin/action.rb', line 5 def model @model end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/upmin/action.rb', line 6 def name @name end |
Instance Method Details
#parameters ⇒ Object Also known as: arguments
21 22 23 24 25 26 27 28 |
# File 'lib/upmin/action.rb', line 21 def parameters return @parameters if defined?(@parameters) @parameters = [] model.method(name).parameters.each do |param_type, param_name| @parameters << Upmin::Parameter.new(self, param_name, type: param_type) end return @parameters end |
#path ⇒ Object
17 18 19 |
# File 'lib/upmin/action.rb', line 17 def path return upmin_action_path(klass: model.model_class_name, id: model.id, method: name) end |
#perform(arguments) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/upmin/action.rb', line 31 def perform(arguments) array = [] parameters.each do |parameter| if parameter.type == :req unless arguments[parameter.name] raise Upmin::MissingArgument.new(parameter.name) end array << arguments[parameter.name] elsif parameter.type == :opt array << arguments[parameter.name] if arguments[parameter.name] else # :block - skip it end end return model.send(name, *array) end |
#title ⇒ Object
13 14 15 |
# File 'lib/upmin/action.rb', line 13 def title return name.to_s.humanize end |