Class: Resty::Actions
- Inherits:
-
Object
- Object
- Resty::Actions
- Defined in:
- lib/resty/actions.rb
Instance Method Summary collapse
- #exist?(name) ⇒ Boolean
-
#initialize(definitions) ⇒ Actions
constructor
A new instance of Actions.
- #perform!(name, parameters = nil) ⇒ Object
Constructor Details
#initialize(definitions) ⇒ Actions
Returns a new instance of Actions.
3 4 5 |
# File 'lib/resty/actions.rb', line 3 def initialize(definitions) @definitions = definitions || {} end |
Instance Method Details
#exist?(name) ⇒ Boolean
23 24 25 |
# File 'lib/resty/actions.rb', line 23 def exist?(name) @definitions.key?(name) end |
#perform!(name, parameters = nil) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/resty/actions.rb', line 7 def perform!(name, parameters = nil) raise "unknown action #{name}" unless exist?(name) href = @definitions[name].fetch(':href') { raise "no href for action #{name}" } method = @definitions[name].fetch(':method') { raise "no method for action #{name}" } if parameters body = parameters.to_json mimetype = 'application/json' else body = nil mimetype = nil end Resty.wrap(Resty::Transport.request_json(href, method, body, mimetype)) end |