Class: Wordnik::Operation
- Extended by:
- ActiveModel::Naming
- Includes:
- ActiveModel::Conversion, ActiveModel::Validations
- Defined in:
- lib/wordnik/operation.rb
Instance Attribute Summary collapse
-
#category ⇒ Object
Returns the value of attribute category.
-
#deprecated ⇒ Object
Returns the value of attribute deprecated.
-
#endpoint ⇒ Object
Returns the value of attribute endpoint.
-
#error_responses ⇒ Object
Returns the value of attribute error_responses.
-
#http_method ⇒ Object
Returns the value of attribute http_method.
-
#nickname ⇒ Object
Returns the value of attribute nickname.
-
#notes ⇒ Object
Returns the value of attribute notes.
-
#open ⇒ Object
Returns the value of attribute open.
-
#parameters ⇒ Object
Returns the value of attribute parameters.
-
#response ⇒ Object
Returns the value of attribute response.
-
#response_class ⇒ Object
Returns the value of attribute response_class.
-
#response_type_internal ⇒ Object
Returns the value of attribute response_type_internal.
-
#summary ⇒ Object
Returns the value of attribute summary.
Instance Method Summary collapse
- #get? ⇒ Boolean
-
#initialize(endpoint, attributes = {}) ⇒ Operation
constructor
A new instance of Operation.
- #optional_kwargs ⇒ Object
-
#persisted? ⇒ Boolean
It’s an ActiveModel thing..
- #positional_parameter_names ⇒ Object
- #required_kwargs ⇒ Object
-
#sandboxable? ⇒ Boolean
Can this operation be run in the sandbox?.
-
#slug ⇒ Object
A globally unique identifier for the operation.
Constructor Details
#initialize(endpoint, attributes = {}) ⇒ Operation
Returns a new instance of Operation.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/wordnik/operation.rb', line 14 def initialize(endpoint, attributes = {}) self.endpoint = endpoint attributes.each do |name, value| send("#{name.to_s.underscore.to_sym}=", value) end # munge that meth! self.http_method = self.http_method.to_s.downcase # Generate OperationParameter instances from JSON if self.parameters self.parameters = self.parameters.map do |parameterData| OperationParameter.new(parameterData) end else self.parameters = [] end self.nickname = self.nickname.underscore end |
Instance Attribute Details
#category ⇒ Object
Returns the value of attribute category.
9 10 11 |
# File 'lib/wordnik/operation.rb', line 9 def category @category end |
#deprecated ⇒ Object
Returns the value of attribute deprecated.
9 10 11 |
# File 'lib/wordnik/operation.rb', line 9 def deprecated @deprecated end |
#endpoint ⇒ Object
Returns the value of attribute endpoint.
9 10 11 |
# File 'lib/wordnik/operation.rb', line 9 def endpoint @endpoint end |
#error_responses ⇒ Object
Returns the value of attribute error_responses.
9 10 11 |
# File 'lib/wordnik/operation.rb', line 9 def error_responses @error_responses end |
#http_method ⇒ Object
Returns the value of attribute http_method.
9 10 11 |
# File 'lib/wordnik/operation.rb', line 9 def http_method @http_method end |
#nickname ⇒ Object
Returns the value of attribute nickname.
9 10 11 |
# File 'lib/wordnik/operation.rb', line 9 def nickname @nickname end |
#notes ⇒ Object
Returns the value of attribute notes.
9 10 11 |
# File 'lib/wordnik/operation.rb', line 9 def notes @notes end |
#open ⇒ Object
Returns the value of attribute open.
9 10 11 |
# File 'lib/wordnik/operation.rb', line 9 def open @open end |
#parameters ⇒ Object
Returns the value of attribute parameters.
9 10 11 |
# File 'lib/wordnik/operation.rb', line 9 def parameters @parameters end |
#response ⇒ Object
Returns the value of attribute response.
9 10 11 |
# File 'lib/wordnik/operation.rb', line 9 def response @response end |
#response_class ⇒ Object
Returns the value of attribute response_class.
9 10 11 |
# File 'lib/wordnik/operation.rb', line 9 def response_class @response_class end |
#response_type_internal ⇒ Object
Returns the value of attribute response_type_internal.
9 10 11 |
# File 'lib/wordnik/operation.rb', line 9 def response_type_internal @response_type_internal end |
#summary ⇒ Object
Returns the value of attribute summary.
9 10 11 |
# File 'lib/wordnik/operation.rb', line 9 def summary @summary end |
Instance Method Details
#get? ⇒ Boolean
41 42 43 |
# File 'lib/wordnik/operation.rb', line 41 def get? self.http_method.downcase == "get" end |
#optional_kwargs ⇒ Object
68 69 70 71 72 73 |
# File 'lib/wordnik/operation.rb', line 68 def optional_kwargs self.parameters.map do |parameter| next if parameter.required? parameter end.compact end |
#persisted? ⇒ Boolean
It’s an ActiveModel thing..
51 52 53 |
# File 'lib/wordnik/operation.rb', line 51 def persisted? false end |
#positional_parameter_names ⇒ Object
55 56 57 |
# File 'lib/wordnik/operation.rb', line 55 def positional_parameter_names self.parameters.select(&:positional?).compact.map(&:name) end |
#required_kwargs ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/wordnik/operation.rb', line 59 def required_kwargs self.parameters.map do |parameter| next if parameter.name.to_sym == :format next if parameter.positional? next unless parameter.required? parameter end.compact end |
#sandboxable? ⇒ Boolean
Can this operation be run in the sandbox?
46 47 48 |
# File 'lib/wordnik/operation.rb', line 46 def sandboxable? self.get? end |
#slug ⇒ Object
A globally unique identifier for the operation
37 38 39 |
# File 'lib/wordnik/operation.rb', line 37 def slug [self.endpoint.resource.name, self.nickname].join("_") end |