module NStore::ClassMethods
List of Class methods going to be included above
Public Instance Methods
_nstore_generate_accessors(attribute, flat_accessors, prefix, stringify)
click to toggle source
# File lib/nstore.rb, line 43 def _nstore_generate_accessors(attribute, flat_accessors, prefix, stringify) flat_accessors.each do |keys| keys.reject!(&:nil?) keys.map!(&:to_s) if stringify define_method("#{prefix ? "#{attribute}_" : ''}#{keys.join('_')}=".to_sym) do |value| write_nstore_attribute(attribute, keys, value) end define_method("#{prefix ? "#{attribute}_" : ''}#{keys.join('_')}".to_sym) do read_nstore_attribute(attribute, keys) end end end
nstore(attribute, options)
click to toggle source
# File lib/nstore.rb, line 31 def nstore(attribute, options) accessors = options[:accessors] prefix = options.fetch(:prefix, false) stringify = options.fetch(:stringify, true) accessors = { nil => accessors } if accessors.is_a? Array flat_accessors = [] deep_flatten(accessors, [], flat_accessors) attribute = attribute.to_s if stringify _nstore_generate_accessors(attribute, flat_accessors, prefix, stringify) end
Private Instance Methods
_array_wrap(object)
click to toggle source
@return [Array]
# File lib/nstore.rb, line 73 def _array_wrap(object) if object.nil? [] elsif object.respond_to?(:to_ary) object.to_ary || [object] else [object] end end
deep_flatten(tree, path, result)
click to toggle source
# File lib/nstore.rb, line 60 def deep_flatten(tree, path, result) tree.each do |key, value| _array_wrap(value).each do |e| if e.is_a? Hash deep_flatten(e, path + [key], result) else result << path + [key, e] end end end end