Class: Typesmith::SimpleProperty
- Inherits:
-
BaseProperty
- Object
- BaseProperty
- Typesmith::SimpleProperty
- Defined in:
- lib/typesmith/simple_property.rb
Direct Known Subclasses
Constant Summary
Constants inherited from BaseProperty
Instance Attribute Summary collapse
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Attributes inherited from BaseProperty
Instance Method Summary collapse
-
#initialize(name, type, optional: false) ⇒ SimpleProperty
constructor
A new instance of SimpleProperty.
- #process_value(value) ⇒ Object
- #to_typescript ⇒ Object
Constructor Details
#initialize(name, type, optional: false) ⇒ SimpleProperty
Returns a new instance of SimpleProperty.
7 8 9 10 11 |
# File 'lib/typesmith/simple_property.rb', line 7 def initialize(name, type, optional: false) super(name, optional: optional) @type = type self.class.validate_type(type) end |
Instance Attribute Details
#type ⇒ Object (readonly)
Returns the value of attribute type.
5 6 7 |
# File 'lib/typesmith/simple_property.rb', line 5 def type @type end |
Instance Method Details
#process_value(value) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/typesmith/simple_property.rb', line 17 def process_value(value) if type.is_a?(Class) && type < Definition type.new(value).attributes else value end end |
#to_typescript ⇒ Object
13 14 15 |
# File 'lib/typesmith/simple_property.rb', line 13 def to_typescript "#{camelized_name}#{optional_suffix}: #{get_type_string(type)};" end |