Class: Typesmith::NestedProperty
- Inherits:
-
BaseProperty
- Object
- BaseProperty
- Typesmith::NestedProperty
- Defined in:
- lib/typesmith/nested_property.rb
Constant Summary
Constants inherited from BaseProperty
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
Attributes inherited from BaseProperty
Instance Method Summary collapse
-
#initialize(name, block, optional: false) ⇒ NestedProperty
constructor
A new instance of NestedProperty.
- #process_value(value) ⇒ Object
- #to_typescript ⇒ Object
Constructor Details
#initialize(name, block, optional: false) ⇒ NestedProperty
Returns a new instance of NestedProperty.
7 8 9 10 |
# File 'lib/typesmith/nested_property.rb', line 7 def initialize(name, block, optional: false) super(name, optional: optional) @block = block end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
5 6 7 |
# File 'lib/typesmith/nested_property.rb', line 5 def block @block end |
Instance Method Details
#process_value(value) ⇒ Object
24 25 26 27 28 |
# File 'lib/typesmith/nested_property.rb', line 24 def process_value(value) nested_class = Class.new(Definition) nested_class.class_eval(&block) nested_class.new(value).attributes end |
#to_typescript ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/typesmith/nested_property.rb', line 12 def to_typescript nested_class = Class.new(Definition) nested_class.class_eval(&block) [ "#{camelized_name}#{optional_suffix}: {", nested_class.send(:generate_properties, nested_class.properties).split("\n").map do |line| " #{line}" end.join("\n"), "};" ].join("\n") end |