Module: Sequencescape::Api::Actions
- Included in:
- Sequencescape::Api::Associations::HasMany::AssociationProxy, ConnectionFactory, Resource, ResourceModelProxy
- Defined in:
- lib/sequencescape-api/actions.rb
Instance Method Summary (collapse)
- - (Object) has_create_action(name = :create!, options = {})
- - (Object) has_update_action(name, options = {})
Instance Method Details
- (Object) has_create_action(name = :create!, options = {})
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/sequencescape-api/actions.rb', line 2 def has_create_action(name = :create!, = {}) action = [:action] || :create line = __LINE__ + 1 class_eval(%Q{ def #{name}(attributes = nil) url = actions.try(#{action.to_sym.inspect}) or raise Sequencescape::Api::Error, "Cannot perform #{action} without an URL" new(attributes || {}, false).tap do |object| object.save!(:url => url) end end }, __FILE__, line) end |
- (Object) has_update_action(name, options = {})
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/sequencescape-api/actions.rb', line 18 def has_update_action(name, = {}) api_method = [:verb] == :create ? :create : :update action = [:action] || :update line = __LINE__ + 1 class_eval(%Q{ def #{name}(body = nil) update_from_json(body || {}, false) modify!(:action => #{action.to_sym.inspect}, :http_verb => #{api_method.to_sym.inspect}) end }, __FILE__, line) end |