Class: Lookbook::TagStore

Inherits:
Object
  • Object
show all
Defined in:
lib/lookbook/stores/tag_store.rb

Constant Summary collapse

CONFIG_FILE =
"config/tags.yml"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = nil) ⇒ TagStore

Returns a new instance of TagStore.



8
9
10
11
# File 'lib/lookbook/stores/tag_store.rb', line 8

def initialize(config = nil)
  @store = {}
  config.to_h.each { |k, opts| add_tag(k, opts, true) }
end

Instance Attribute Details

#storeObject (readonly)



5
6
7
# File 'lib/lookbook/stores/tag_store.rb', line 5

def store
  @store
end

Class Method Details

.default_configObject



30
31
32
# File 'lib/lookbook/stores/tag_store.rb', line 30

def self.default_config
  ConfigLoader.call(CONFIG_FILE)
end

.init_from_configObject



26
27
28
# File 'lib/lookbook/stores/tag_store.rb', line 26

def self.init_from_config
  new(default_config)
end

Instance Method Details

#add_tag(name, opts = nil, is_system = false) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/lookbook/stores/tag_store.rb', line 13

def add_tag(name, opts = nil, is_system = false)
  name = name.to_sym
  if store.key?(name)
    raise ConfigError.new("tag with name '#{name}' already exists", scope: "tags.config")
  else
    store[name] = build_config(name, opts, is_system)
  end
end

#get_tag(name) ⇒ Object



22
23
24
# File 'lib/lookbook/stores/tag_store.rb', line 22

def get_tag(name)
  store[name.to_sym]
end