Class: OReflect::Action

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Accessors

included

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

#endpointObject (readonly)

Returns the value of attribute endpoint.



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

def endpoint
  @endpoint
end

#examplesObject (readonly)

Returns the value of attribute examples.



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

def examples
  @examples
end

#form_paramsObject (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_paramsObject (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_hashObject



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

#example(&block) ⇒ Object



22
23
24
# File 'lib/oreflect/action.rb', line 22

def example(&block)
  @examples << Example.new(&block)
end

#query(key, &block) ⇒ Object



26
27
28
# File 'lib/oreflect/action.rb', line 26

def query(key, &block)
  @query_params << Param.new(key, &block)
end