class Fire::NestedModel
Public Class Methods
all()
click to toggle source
# File lib/model/nested/base.rb, line 88 def all query end
collection_name()
click to toggle source
# File lib/model/nested/base.rb, line 66 def collection_name parent.collection_name end
folder()
click to toggle source
# File lib/model/nested/base.rb, line 70 def folder path_value_param(self.nested_options.folder ? self.nested_options.folder : default_folder_name) end
folder_content(parent)
click to toggle source
# File lib/model/nested/base.rb, line 74 def folder_content(parent) levels_count = (path_keys || []).count nested_folder = parent.send(folder) || {} objects = self.down_levels(nested_folder, levels_count) objects.map{|parent_original| full_data = parent_original.clone.merge(parent.path_data) new(full_data, parent_original) } end
has_path_keys(*keys)
click to toggle source
Calls superclass method
Fire::Model::has_path_keys
# File lib/model/nested/base.rb, line 47 def has_path_keys(*keys) raise ParentModelNotSetError.new(self) unless self.parent super(*keys) keys.each do |key| raise DuplicatedParentPathKeyError.new(key, self.parent) if self.parent.all_path_keys.include?(key) end end
id_key()
click to toggle source
# File lib/model/nested/base.rb, line 32 def self.id_key self.id_key_name || "#{self.name.demodulize.singularize.dasherize.downcase}_id".to_sym end
in_collection(name)
click to toggle source
# File lib/model/nested/base.rb, line 43 def in_collection(name) raise CollectionIsSetError.new(self) end
nested_in(parent, options={})
click to toggle source
# File lib/model/nested/base.rb, line 55 def nested_in(parent, options={}) self.parent = parent self.nested_options = OpenStruct.new(options) self.parent.has_nested(self) validate_id_key! end
new(hash={}, parent_original={})
click to toggle source
Calls superclass method
Fire::Model::new
# File lib/model/nested/base.rb, line 6 def initialize(hash={}, parent_original={}) @parent_original = parent_original super(hash) end
own_path_keys()
click to toggle source
Calls superclass method
Fire::Model::own_path_keys
# File lib/model/nested/base.rb, line 62 def own_path_keys parent.all_path_keys + [ folder ] + super() end
query(params={}, &filter_condition)
click to toggle source
# File lib/model/nested/base.rb, line 84 def query(params={}, &filter_condition) raise QueryingNotSupportedError.new end
Protected Class Methods
default_folder_name()
click to toggle source
# File lib/model/nested/base.rb, line 94 def default_folder_name name.demodulize.pluralize.dasherize end
validate_id_key!()
click to toggle source
# File lib/model/nested/base.rb, line 98 def validate_id_key! raise DuplicatedIdKeyError.new(self.id_key, self.parent) if self.parent.all_path_keys.include?(id_key) end
Public Instance Methods
method_missing(*args)
click to toggle source
Calls superclass method
# File lib/model/nested/base.rb, line 103 def method_missing(*args) if args.first.to_s == self.class.folder self.class.folder else super end end
nested_options()
click to toggle source
# File lib/model/nested/base.rb, line 28 def nested_options self.class.nested_options end
save()
click to toggle source
Calls superclass method
Fire::Model#save
# File lib/model/nested/base.rb, line 23 def save sync_parent super end
saving_data()
click to toggle source
Calls superclass method
Fire::NestedParent#saving_data
# File lib/model/nested/base.rb, line 15 def saving_data return super() if nested_options.parent_values self.class.parent.all_path_keys.each_with_object(data.clone) do |k, res| res.delete(k) end end
set_id_key(value)
click to toggle source
Calls superclass method
Fire::Model::set_id_key
# File lib/model/nested/base.rb, line 36 def set_id_key(value) raise ParentModelNotSetError.new(self) unless self.parent validate_id_key! super(value) end
sync_parent()
click to toggle source
# File lib/model/nested/base.rb, line 11 def sync_parent @parent_original.merge!(saving_data) end