Class: Tush::ModelStore
- Inherits:
-
Object
- Object
- Tush::ModelStore
- Defined in:
- lib/tush/model_store.rb
Overview
This holds the collection of models that will be exported.
Instance Attribute Summary collapse
-
#blacklisted_models ⇒ Object
Returns the value of attribute blacklisted_models.
-
#copy_only_models ⇒ Object
Returns the value of attribute copy_only_models.
-
#model_wrappers ⇒ Object
Returns the value of attribute model_wrappers.
Instance Method Summary collapse
- #export ⇒ Object
-
#initialize(opts = {}) ⇒ ModelStore
constructor
A new instance of ModelStore.
- #object_in_stack?(model_instance) ⇒ Boolean
- #push(model_instance, parent_wrapper = nil) ⇒ Object
- #push_array(model_array) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ ModelStore
Returns a new instance of ModelStore.
10 11 12 13 14 |
# File 'lib/tush/model_store.rb', line 10 def initialize(opts={}) self.blacklisted_models = opts[:blacklisted_models] || [] self.copy_only_models = opts[:copy_only_models] || [] self.model_wrappers = [] end |
Instance Attribute Details
#blacklisted_models ⇒ Object
Returns the value of attribute blacklisted_models.
8 9 10 |
# File 'lib/tush/model_store.rb', line 8 def blacklisted_models @blacklisted_models end |
#copy_only_models ⇒ Object
Returns the value of attribute copy_only_models.
8 9 10 |
# File 'lib/tush/model_store.rb', line 8 def copy_only_models @copy_only_models end |
#model_wrappers ⇒ Object
Returns the value of attribute model_wrappers.
8 9 10 |
# File 'lib/tush/model_store.rb', line 8 def model_wrappers @model_wrappers end |
Instance Method Details
#export ⇒ Object
52 53 54 |
# File 'lib/tush/model_store.rb', line 52 def export { :model_wrappers => self.model_wrappers.map { |model_wrapper| model_wrapper.export } } end |
#object_in_stack?(model_instance) ⇒ Boolean
42 43 44 45 46 47 48 49 50 |
# File 'lib/tush/model_store.rb', line 42 def object_in_stack?(model_instance) self.model_wrappers.each do |model_wrapper| next if model_instance.class != model_wrapper.model_class next if model_instance.attributes != model_wrapper.model_attributes return true end return false end |
#push(model_instance, parent_wrapper = nil) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/tush/model_store.rb', line 20 def push(model_instance, parent_wrapper=nil) return if self.object_in_stack?(model_instance) return if self.blacklisted_models.include?(model_instance.class) model_wrapper = ModelWrapper.new(:model => model_instance) if parent_wrapper and parent_wrapper.model_trace.any? model_wrapper.add_model_trace_list(parent_wrapper.model_trace) model_wrapper.add_model_trace(parent_wrapper) elsif parent_wrapper model_wrapper.add_model_trace(parent_wrapper) end model_wrappers.push(model_wrapper) return if self.copy_only_models.include?(model_instance.class) model_wrapper.association_objects.each do |object| self.push(object, model_wrapper) end end |
#push_array(model_array) ⇒ Object
16 17 18 |
# File 'lib/tush/model_store.rb', line 16 def push_array(model_array) model_array.each { |model_instance| self.push(model_instance) } end |