Sha256: e793cc1654001f0b8d5fe89c34d009e0b67f00ae73ff78d82f4c48280d833bf8
Contents?: true
Size: 951 Bytes
Versions: 15
Compression:
Stored size: 951 Bytes
Contents
require 'tengine/core' module Tengine::Core::CollectionAccessible extend ActiveSupport::Concern module ClassMethods def array_text_accessor(attr_name, options = {}) options = {:delimeter => ","}.update(options || {}) delimeter = options[:delimeter] self.module_eval(<<-"EOS", __FILE__, __LINE__ + 1) def #{attr_name}_text #{attr_name} ? #{attr_name}.join(#{delimeter.inspect}) : "" end def #{attr_name}_text=(value) self.#{attr_name} = value.nil? ? [] : value.split(#{delimeter.inspect}).map(&:strip) end EOS end def map_yaml_accessor(attr_name) self.module_eval(<<-"EOS", __FILE__, __LINE__ + 1) def #{attr_name}_yaml YAML.dump({}.update(#{attr_name} || {})) end def #{attr_name}_yaml=(value) self.#{attr_name} = value.blank? ? nil : YAML.load(value) end EOS end end end
Version data entries
15 entries across 15 versions & 1 rubygems