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.



18
19
20
21
# File 'lib/betterdocs/dsl/json_params/param.rb', line 18

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



36
37
38
# File 'lib/betterdocs/dsl/json_params/param.rb', line 36

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

#assign(result, object) ⇒ Object



23
24
25
26
# File 'lib/betterdocs/dsl/json_params/param.rb', line 23

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

#compute_value(object) ⇒ Object



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

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