Class: OReflect::Endpoint

Inherits:
Object
  • Object
show all
Includes:
Accessors
Defined in:
lib/oreflect/endpoint.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Accessors

included

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

#actionsObject (readonly)

Returns the value of attribute actions.



6
7
8
# File 'lib/oreflect/endpoint.rb', line 6

def actions
  @actions
end

#argumentsObject (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_hashObject



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

Returns:

  • (Boolean)


18
19
20
# File 'lib/oreflect/endpoint.rb', line 18

def is_collection?
  @is_collection ? true : false
end