Class: Knish::CollectionConfig
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Knish::CollectionConfig
- Defined in:
- lib/knish/collection_config.rb
Instance Attribute Summary collapse
-
#db_config ⇒ Object
Returns the value of attribute db_config.
-
#model_config ⇒ Object
Returns the value of attribute model_config.
-
#path ⇒ Object
Returns the value of attribute path.
-
#unpersisted_count ⇒ Object
Returns the value of attribute unpersisted_count.
Instance Method Summary collapse
- #collection_root ⇒ Object
- #generic_config ⇒ Object
- #generic_model_configs ⇒ Object
-
#initialize(model_config, path) ⇒ CollectionConfig
constructor
A new instance of CollectionConfig.
- #inspect ⇒ Object
- #member_config(original_config, id = nil) ⇒ Object
- #next_id ⇒ Object
Constructor Details
#initialize(model_config, path) ⇒ CollectionConfig
Returns a new instance of CollectionConfig.
5 6 7 8 9 10 11 |
# File 'lib/knish/collection_config.rb', line 5 def initialize(model_config, path) super(model_config.db_config) @path = path @db_config = model_config.db_config @model_config = model_config @unpersisted_count = 0 end |
Instance Attribute Details
#db_config ⇒ Object
Returns the value of attribute db_config.
3 4 5 |
# File 'lib/knish/collection_config.rb', line 3 def db_config @db_config end |
#model_config ⇒ Object
Returns the value of attribute model_config.
3 4 5 |
# File 'lib/knish/collection_config.rb', line 3 def model_config @model_config end |
#path ⇒ Object
Returns the value of attribute path.
3 4 5 |
# File 'lib/knish/collection_config.rb', line 3 def path @path end |
#unpersisted_count ⇒ Object
Returns the value of attribute unpersisted_count.
3 4 5 |
# File 'lib/knish/collection_config.rb', line 3 def unpersisted_count @unpersisted_count end |
Instance Method Details
#collection_root ⇒ Object
13 14 15 |
# File 'lib/knish/collection_config.rb', line 13 def collection_root "#{model_config.model_root}/#{path}" end |
#generic_config ⇒ Object
25 26 27 |
# File 'lib/knish/collection_config.rb', line 25 def generic_config ModelConfig.new(Knish.config, '') end |
#generic_model_configs ⇒ Object
21 22 23 |
# File 'lib/knish/collection_config.rb', line 21 def generic_model_configs ExistingModels.new(collection_root).ids.map { |id| member_config(generic_config, id) } end |
#inspect ⇒ Object
29 30 31 32 33 |
# File 'lib/knish/collection_config.rb', line 29 def inspect DelegateInspector.new(self, [:db_config, :model_config, :path] ).to_inspect end |
#member_config(original_config, id = nil) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/knish/collection_config.rb', line 35 def member_config(original_config, id=nil) config = original_config.clone config.id = member_id(id) config.path = "#{model_config.path}/#{model_config.id}/#{path}" config end |
#next_id ⇒ Object
17 18 19 |
# File 'lib/knish/collection_config.rb', line 17 def next_id ExistingModels.new(collection_root).next_id + unpersisted_count end |