Class: Typesmith::SimpleProperty

Inherits:
BaseProperty show all
Defined in:
lib/typesmith/simple_property.rb

Direct Known Subclasses

ArrayProperty

Constant Summary

Constants inherited from BaseProperty

BaseProperty::PRIMITIVE_TYPES

Instance Attribute Summary collapse

Attributes inherited from BaseProperty

#name, #optional

Instance Method Summary collapse

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

#typeObject (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_typescriptObject



13
14
15
# File 'lib/typesmith/simple_property.rb', line 13

def to_typescript
  "#{camelized_name}#{optional_suffix}: #{get_type_string(type)};"
end