Module: Tengine::Core::CollectionAccessible::ClassMethods

Defined in:
lib/tengine/core/collection_accessible.rb

Instance Method Summary collapse

Instance Method Details

#array_text_accessor(attr_name, options = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/tengine/core/collection_accessible.rb', line 8

def array_text_accessor(attr_name, options = {})
  options = {:delimeter => ","}.update(options || {})
  delimeter = options[:delimeter]
  self.module_eval("    def \#{attr_name}_text\n      \#{attr_name} ? \#{attr_name}.join(\#{delimeter.inspect}) : \"\"\n    end\n    def \#{attr_name}_text=(value)\n      self.\#{attr_name} = value.nil? ? [] :\n        value.split(\#{delimeter.inspect}).map(&:strip)\n    end\n  EOS\nend\n", __FILE__, __LINE__ + 1)

#map_yaml_accessor(attr_name) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/tengine/core/collection_accessible.rb', line 22

def map_yaml_accessor(attr_name)
  self.module_eval("    def \#{attr_name}_yaml\n      YAML.dump({}.update(\#{attr_name} || {}))\n    end\n    def \#{attr_name}_yaml=(value)\n      self.\#{attr_name} = value.blank? ? nil : YAML.load(value)\n    end\n  EOS\nend\n", __FILE__, __LINE__ + 1)