Module: ApidocoDsl::Documentable

Included in:
ApiDoc, Param, ParamGroup
Defined in:
lib/apidoco_dsl/documentable.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#apiObject

Returns the value of attribute api.



3
4
5
# File 'lib/apidoco_dsl/documentable.rb', line 3

def api
  @api
end

Instance Method Details

#param(key, type:, desc: nil, notes: nil, validations: nil, required: false, &block) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/apidoco_dsl/documentable.rb', line 5

def param(key, type:, desc: nil, notes: nil, validations: nil, required: false, &block)
  this_param = Param.new(
    param_key: key,
    param_type: type,
    param_description: desc,
    param_notes: notes,
    param_required: required,
    param_validations: validations,
    parent: self
  )

  if block_given?
    this_param.instance_exec(this_param, &block)
  end

  push_to << this_param
end

#param_group(group_name) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/apidoco_dsl/documentable.rb', line 42

def param_group(group_name)
  # Param groups seem to have trouble inheriting parentage correctly.
  # This appears to be because the params are "parented" when they are
  # initally defined and when grabbing them here, we need to "re-parent"
  # them...or more accurately, a copy of them.
  #
  # Again, problem, because a single param may itself have multiple layers
  # of child params and groups...
  #
  # An interesting note here is that defining a nested grouping _manually_
  # appears to have the desired effect.

  pg = @api.param_groups[group_name].deep_dup
  #pg.reparent(self) # Make the calling object the top-level parent for every param in this group

  return false unless pg # FIXME This seems more like an autoloading issue than anything?
  pg.params.each do |param|
    push_to << param
  end

end

#property(key, type:, desc: nil, notes: nil, validations: nil, required: true, &block) ⇒ Object

There may be a clever way to do this, preserving key ancestry without duplication…I haven’t found it.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/apidoco_dsl/documentable.rb', line 24

def property(key, type:, desc: nil, notes: nil, validations: nil, required: true, &block)
  this_param = Param.new(
    param_key: key,
    param_type: type,
    param_description: desc,
    param_notes: notes,
    param_required: required,
    param_validations: validations,
    parent: self
  )

  if block_given?
    this_param.instance_exec(this_param, &block)
  end

  push_to << this_param
end