Class: OReflect::Endpoint
- Inherits:
-
Object
- Object
- OReflect::Endpoint
- Includes:
- Accessors
- Defined in:
- lib/oreflect/endpoint.rb
Instance Attribute Summary collapse
-
#actions ⇒ Object
readonly
Returns the value of attribute actions.
-
#arguments ⇒ Object
readonly
Returns the value of attribute arguments.
Instance Method Summary collapse
- #action(method, id = nil, &block) ⇒ Object
- #arg(key, &block) ⇒ Object
- #as_hash ⇒ Object
-
#initialize(template, is_collection = false, &block) ⇒ Endpoint
constructor
A new instance of Endpoint.
- #is_collection? ⇒ Boolean
Methods included from Accessors
Constructor Details
#initialize(template, is_collection = false, &block) ⇒ Endpoint
Returns a new instance of Endpoint.
10 11 12 13 14 15 16 |
# File 'lib/oreflect/endpoint.rb', line 10 def initialize(template, is_collection = false, &block) @template = template @is_collection = is_collection @actions = [] @arguments = [] instance_eval(&block) if block_given? end |
Instance Attribute Details
#actions ⇒ Object (readonly)
Returns the value of attribute actions.
6 7 8 |
# File 'lib/oreflect/endpoint.rb', line 6 def actions @actions end |
#arguments ⇒ Object (readonly)
Returns the value of attribute arguments.
6 7 8 |
# File 'lib/oreflect/endpoint.rb', line 6 def arguments @arguments end |
Instance Method Details
#action(method, id = nil, &block) ⇒ Object
26 27 28 |
# File 'lib/oreflect/endpoint.rb', line 26 def action(method, id = nil, &block) @actions << Action.new(method, id, self, &block) end |
#arg(key, &block) ⇒ Object
22 23 24 |
# File 'lib/oreflect/endpoint.rb', line 22 def arg(key, &block) @arguments << Param.new(key, &block) end |
#as_hash ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/oreflect/endpoint.rb', line 30 def as_hash h = {} h[:name] = name h[:description] = description h[:template] = template h[:is_collection] = is_collection? h[:arguments] = arguments.inject({}) do |hsh, arg| hsh.merge(arg.key => arg.as_hash(:is_required)) end h[:actions] = actions.map { |action| action.as_hash } h end |
#is_collection? ⇒ Boolean
18 19 20 |
# File 'lib/oreflect/endpoint.rb', line 18 def is_collection? @is_collection ? true : false end |