Module: Atomsphere::Action::InstanceMethods
- Defined in:
- lib/atomsphere/action.rb
Class Method Summary collapse
Instance Method Summary collapse
- #action(a) ⇒ Object
- #api_method(m) ⇒ Object
- #one_of(*params) ⇒ Object
- #optional(*params) ⇒ Object
- #required(*params) ⇒ Object
Class Method Details
.extended(base) ⇒ Object
75 76 77 78 79 80 81 82 83 84 |
# File 'lib/atomsphere/action.rb', line 75 def self.extended base %w(required one_of optional).each do |m| base.class_variable_set :"@@#{m}", [] end method_name = base.name.split('::').last.snakecase Atomsphere.define_singleton_method(method_name) do |*params| base.new(*params).run end end |
Instance Method Details
#action(a) ⇒ Object
86 87 88 |
# File 'lib/atomsphere/action.rb', line 86 def action a class_variable_set :@@action, a end |
#api_method(m) ⇒ Object
90 91 92 |
# File 'lib/atomsphere/action.rb', line 90 def api_method m class_variable_set :@@api_method, m end |
#one_of(*params) ⇒ Object
108 109 110 111 112 113 114 115 |
# File 'lib/atomsphere/action.rb', line 108 def one_of *params if params.size < 2 raise ArgumentError, "one_of requires two or more parameters" end class_variable_get(:@@one_of) << [*params] params.each{ |param| attr_accessor param } end |
#optional(*params) ⇒ Object
101 102 103 104 105 106 |
# File 'lib/atomsphere/action.rb', line 101 def optional *params params.each do |param| class_variable_get(:@@optional) << param attr_accessor param end end |
#required(*params) ⇒ Object
94 95 96 97 98 99 |
# File 'lib/atomsphere/action.rb', line 94 def required *params params.each do |param| class_variable_get(:@@required) << param attr_accessor param end end |