Module: NStore::ClassMethods

Defined in:
lib/nstore.rb

Overview

List of Class methods going to be included above

Instance Method Summary collapse

Instance Method Details

#_nstore_generate_accessors(attribute, flat_accessors, prefix, stringify) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/nstore.rb', line 41

def _nstore_generate_accessors(attribute, flat_accessors, prefix, stringify)
  flat_accessors.each do |keys|
    define_method("#{prefix ? "#{attribute}_" : ''}#{keys.join('_')}=".to_sym) do |value|
      keys.map!(&:to_s) if stringify
      write_nstore_attribute(attribute, keys, value)
    end

    define_method("#{prefix ? "#{attribute}_" : ''}#{keys.join('_')}".to_sym) do
      keys.map!(&:to_s) if stringify
      read_nstore_attribute(attribute, keys)
    end
  end
end

#nstore(attribute, options) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/nstore.rb', line 31

def nstore(attribute, options)
  prefix    = options.fetch(:prefix, false)
  stringify = options.fetch(:stringify, false)
  accessors = options[:accessors]

  flat_accessors = []
  deep_flatten(accessors, [], flat_accessors)
  _nstore_generate_accessors(attribute, flat_accessors, prefix, stringify)
end