Class: Betterdocs::Dsl::JsonParams::Param

Inherits:
Representer
  • Object
show all
Extended by:
Tins::DSLAccessor
Includes:
Common, Naming
Defined in:
lib/betterdocs/dsl/json_params/param.rb

Instance Attribute Summary

Attributes included from Naming

#options

Attributes inherited from Representer

#name, #representer

Instance Method Summary collapse

Methods included from Naming

#below_path, #full_name, #nesting_name, #path, #public_name

Methods included from Common

#set_context

Methods inherited from Representer

#assign?

Constructor Details

#initialize(representer, name, options, &block) ⇒ Param

Returns a new instance of Param.



16
17
18
19
# File 'lib/betterdocs/dsl/json_params/param.rb', line 16

def initialize(representer, name, options, &block)
  super
  types Betterdocs::Dsl::JsonTypeMapper.map_types(types)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Betterdocs::Dsl::Common

Instance Method Details

#add_to_collector(collector) ⇒ Object



34
35
36
# File 'lib/betterdocs/dsl/json_params/param.rb', line 34

def add_to_collector(collector)
  collector.params[name] = self
end

#assign(result, object) ⇒ Object



21
22
23
24
# File 'lib/betterdocs/dsl/json_params/param.rb', line 21

def assign(result, object)
  assign?(object) or return
  result[name] = compute_value(object)
end

#compute_value(object) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/betterdocs/dsl/json_params/param.rb', line 26

def compute_value(object)
  value = object.__send__(name)
  if ActiveSupport::TimeWithZone === value
    value.extend Betterdocs::JsonTimeWithZone
  end
  value
end