Class: MetaTypes::MetaProperty

Inherits:
Object
  • Object
show all
Defined in:
lib/meta_types/meta_property.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(meta_properties, sid) ⇒ MetaProperty

Returns a new instance of MetaProperty.



6
7
8
9
10
# File 'lib/meta_types/meta_property.rb', line 6

def initialize(meta_properties, sid)
  self.meta_properties = meta_properties
  self.sid = sid
  self.meta_type_property = MetaTypeProperty[sid]
end

Instance Attribute Details

#meta_propertiesObject

Returns the value of attribute meta_properties.



2
3
4
# File 'lib/meta_types/meta_property.rb', line 2

def meta_properties
  @meta_properties
end

#meta_type_propertyObject

Returns the value of attribute meta_type_property.



3
4
5
# File 'lib/meta_types/meta_property.rb', line 3

def meta_type_property
  @meta_type_property
end

#sidObject

Returns the value of attribute sid.



4
5
6
# File 'lib/meta_types/meta_property.rb', line 4

def sid
  @sid
end

Instance Method Details

#choicesObject



20
21
22
23
# File 'lib/meta_types/meta_property.rb', line 20

def choices()
  ch = meta_type_property.choices.presence
  ch && ch.split('||').map(&:strip)
end

#valueObject



12
13
14
# File 'lib/meta_types/meta_property.rb', line 12

def value
  meta_type_property.cast(meta_properties.try(:get_value, sid) || meta_type_property.default_value)
end

#value=(val) ⇒ Object



16
17
18
# File 'lib/meta_types/meta_property.rb', line 16

def value=(val)
  meta_properties.set_value(sid, meta_type_property.parse(val))
end