Class: Betterdocs::Dsl::Result::Property
Instance Attribute Summary
Attributes included from Naming
#options
#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
#assign?
Constructor Details
#initialize(representer, name, options, &block) ⇒ Property
Returns a new instance of Property.
19
20
21
22
23
24
25
26
|
# File 'lib/betterdocs/dsl/result/property.rb', line 19
def initialize(representer, name, options, &block)
super
types Betterdocs::Dsl::JsonTypeMapper.map_types(types)
if sr = sub_representer?
sr < Betterdocs::ResultRepresenter or
raise TypeError, "#{sr.inspect} is not a Betterdocs::Result subclass"
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Betterdocs::Dsl::Common
Instance Method Details
#actual_property_name ⇒ Object
32
33
34
|
# File 'lib/betterdocs/dsl/result/property.rb', line 32
def actual_property_name
(options[:as] || name).to_s
end
|
#add_to_collector(collector) ⇒ Object
50
51
52
|
# File 'lib/betterdocs/dsl/result/property.rb', line 50
def add_to_collector(collector)
collector.properties[name] = self
end
|
#assign(result, object) ⇒ Object
36
37
38
39
|
# File 'lib/betterdocs/dsl/result/property.rb', line 36
def assign(result, object)
assign?(object) or return
result[actual_property_name] = compute_value(object)
end
|
#compute_value(object) ⇒ Object
41
42
43
44
45
46
47
48
|
# File 'lib/betterdocs/dsl/result/property.rb', line 41
def compute_value(object)
value = object.__send__(name)
if !value.nil? && represent_with
represent_with.hashify(value)
else
value
end
end
|
#sub_representer? ⇒ Boolean
28
29
30
|
# File 'lib/betterdocs/dsl/result/property.rb', line 28
def sub_representer?
represent_with
end
|