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

Version Path
tengine_core-1.2.2 lib/tengine/core/collection_accessible.rb
tengine_core-1.2.1 lib/tengine/core/collection_accessible.rb
tengine_core-1.2.0 lib/tengine/core/collection_accessible.rb
tengine_core-1.1.0 lib/tengine/core/collection_accessible.rb
tengine_core-0.5.39 lib/tengine/core/collection_accessible.rb
tengine_core-0.5.38 lib/tengine/core/collection_accessible.rb
tengine_core-0.5.37 lib/tengine/core/collection_accessible.rb
tengine_core-0.5.36 lib/tengine/core/collection_accessible.rb
tengine_core-0.5.35 lib/tengine/core/collection_accessible.rb
tengine_core-0.5.34 lib/tengine/core/collection_accessible.rb
tengine_core-0.5.33 lib/tengine/core/collection_accessible.rb
tengine_core-0.5.32 lib/tengine/core/collection_accessible.rb
tengine_core-0.5.31 lib/tengine/core/collection_accessible.rb
tengine_core-0.5.30 lib/tengine/core/collection_accessible.rb
tengine_core-0.5.28 lib/tengine/core/collection_accessible.rb