Class: Knish::CollectionConfig

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/knish/collection_config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_configObject

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_configObject

Returns the value of attribute model_config.



3
4
5
# File 'lib/knish/collection_config.rb', line 3

def model_config
  @model_config
end

#pathObject

Returns the value of attribute path.



3
4
5
# File 'lib/knish/collection_config.rb', line 3

def path
  @path
end

#unpersisted_countObject

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_rootObject



13
14
15
# File 'lib/knish/collection_config.rb', line 13

def collection_root
  "#{model_config.model_root}/#{path}"
end

#generic_configObject



25
26
27
# File 'lib/knish/collection_config.rb', line 25

def generic_config
  ModelConfig.new(Knish.config, '')
end

#generic_model_configsObject



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

#inspectObject



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_idObject



17
18
19
# File 'lib/knish/collection_config.rb', line 17

def next_id
  ExistingModels.new(collection_root).next_id + unpersisted_count
end