Module: Imperator::Command::RestHelper::ClassMethods
- Defined in:
- lib/imperator/command/rest_helper.rb
Instance Method Summary collapse
- #create_action(&block) ⇒ Object
- #delete_action(&block) ⇒ Object
- #for_class(clazz) ⇒ Object
- #object_class ⇒ Object
- #on_error(&block) ⇒ Object
- #rest_action(name, &block) ⇒ Object
- #update_action(&block) ⇒ Object
Instance Method Details
#create_action(&block) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/imperator/command/rest_helper.rb', line 12 def create_action &block action do object_class.create attribute_set if object_class instance_eval &block if block_given? end end |
#delete_action(&block) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/imperator/command/rest_helper.rb', line 30 def delete_action &block action do find_object.delete instance_eval &block if block_given? end end |
#for_class(clazz) ⇒ Object
45 46 47 |
# File 'lib/imperator/command/rest_helper.rb', line 45 def for_class clazz @object_class = clazz end |
#object_class ⇒ Object
49 50 51 |
# File 'lib/imperator/command/rest_helper.rb', line 49 def object_class @object_class ||= filtered_class_name end |
#on_error(&block) ⇒ Object
41 42 43 |
# File 'lib/imperator/command/rest_helper.rb', line 41 def on_error &block define_method(:on_error, &block) end |
#rest_action(name, &block) ⇒ Object
37 38 39 |
# File 'lib/imperator/command/rest_helper.rb', line 37 def rest_action name, &block send("#{name}_action", &block) if supported_rest_actions.include? name.to_sym end |
#update_action(&block) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/imperator/command/rest_helper.rb', line 19 def update_action &block action do begin find_object.update_attributes attribute_set if find_object instance_eval &block if block_given? rescue Imperator::ResourceNotFoundError => e on_error e end end end |