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.
25
26
27
28
29
30
31
32
|
# File 'lib/betterdocs/dsl/result/property.rb', line 25
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
38
39
40
|
# File 'lib/betterdocs/dsl/result/property.rb', line 38
def actual_property_name
(options[:as] || name).to_s
end
|
#add_to_collector(collector) ⇒ Object
64
65
66
|
# File 'lib/betterdocs/dsl/result/property.rb', line 64
def add_to_collector(collector)
collector.properties[name] = self
end
|
#assign(result, object) ⇒ Object
42
43
44
45
46
|
# File 'lib/betterdocs/dsl/result/property.rb', line 42
def assign(result, object)
assign?(object) or return
result[actual_property_name] = compute_value(object)
self
end
|
#compute_value(object) ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/betterdocs/dsl/result/property.rb', line 48
def compute_value(object)
value = object.__send__(name)
value.nil? and return
if represent_with
represent_with.hashify(value)
elsif value.respond_to?(:iso8601)
value.extend Betterdocs::JsonTimeWithZone
else
sanitizer.sanitize(value)
end
end
|
#sanitizer ⇒ Object
60
61
62
|
# File 'lib/betterdocs/dsl/result/property.rb', line 60
def sanitizer
Betterdocs::Sanitizer.new(&sanitize)
end
|
#sub_representer? ⇒ Boolean
34
35
36
|
# File 'lib/betterdocs/dsl/result/property.rb', line 34
def sub_representer?
represent_with
end
|