Class: OReflect::Action
- Inherits:
-
Object
- Object
- OReflect::Action
- Includes:
- Accessors
- Defined in:
- lib/oreflect/action.rb
Instance Attribute Summary collapse
-
#endpoint ⇒ Object
readonly
Returns the value of attribute endpoint.
-
#examples ⇒ Object
readonly
Returns the value of attribute examples.
-
#form_params ⇒ Object
readonly
Returns the value of attribute form_params.
-
#query_params ⇒ Object
readonly
Returns the value of attribute query_params.
Instance Method Summary collapse
- #as_hash ⇒ Object
- #body(key, &block) ⇒ Object
- #example(&block) ⇒ Object
-
#initialize(method, identifier = nil, endpoint = nil, &block) ⇒ Action
constructor
A new instance of Action.
- #query(key, &block) ⇒ Object
Methods included from Accessors
Constructor Details
#initialize(method, identifier = nil, endpoint = nil, &block) ⇒ Action
Returns a new instance of Action.
12 13 14 15 16 17 18 19 20 |
# File 'lib/oreflect/action.rb', line 12 def initialize(method, identifier = nil, endpoint = nil, &block) @method = method @identifier = identifier @endpoint = endpoint @query_params = [] @form_params = [] @examples = [] instance_eval(&block) if block_given? end |
Instance Attribute Details
#endpoint ⇒ Object (readonly)
Returns the value of attribute endpoint.
6 7 8 |
# File 'lib/oreflect/action.rb', line 6 def endpoint @endpoint end |
#examples ⇒ Object (readonly)
Returns the value of attribute examples.
6 7 8 |
# File 'lib/oreflect/action.rb', line 6 def examples @examples end |
#form_params ⇒ Object (readonly)
Returns the value of attribute form_params.
6 7 8 |
# File 'lib/oreflect/action.rb', line 6 def form_params @form_params end |
#query_params ⇒ Object (readonly)
Returns the value of attribute query_params.
6 7 8 |
# File 'lib/oreflect/action.rb', line 6 def query_params @query_params end |
Instance Method Details
#as_hash ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/oreflect/action.rb', line 34 def as_hash h = {} h[:name] = name h[:identifier] = identifier h[:method] = method h[:is_authenticated] = is_authenticated? h[:description] = description h[:examples] = examples.map { |example| example.as_hash } h[:query_params] = query_params.inject({}) { |hsh, param| hsh.merge(param.key => param.as_hash) } h[:form_params] = form_params.inject({}) { |hsh, param| hsh.merge(param.key => param.as_hash) } h end |
#body(key, &block) ⇒ Object
30 31 32 |
# File 'lib/oreflect/action.rb', line 30 def body(key, &block) @form_params << Param.new(key, &block) end |