Module: Sequencescape::Api::Actions::InstanceActionHelpers
- Defined in:
- lib/sequencescape-api/actions.rb
Instance Method Summary collapse
Instance Method Details
#has_create_action(*args) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/sequencescape-api/actions.rb', line 34 def has_create_action(*args) = args. name = args.first || :create! action = [:action] || :create result_class = 'self' result_class = "api.#{options[:resource]}" if [:resource] 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" #{result_class}.new(attributes || {}, false).tap do |object| object.save!(:url => url) end end }, __FILE__, line) end |
#has_update_action(name, options = {}) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/sequencescape-api/actions.rb', line 55 def has_update_action(name, = {}) api_method = [:verb] == :create ? :create : :update skip_json = [:skip_json]||false 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}, :skip_json => #{skip_json}) end }, __FILE__, line) end |