Class: Lookbook::TagStore
- Inherits:
-
Object
- Object
- Lookbook::TagStore
- Defined in:
- lib/lookbook/stores/tag_store.rb
Constant Summary collapse
- CONFIG_FILE =
"config/tags.yml"
Instance Attribute Summary collapse
- #store ⇒ Object readonly
Class Method Summary collapse
Instance Method Summary collapse
- #add_tag(name, opts = nil, is_system = false) ⇒ Object
- #get_tag(name) ⇒ Object
-
#initialize(config = nil) ⇒ TagStore
constructor
A new instance of TagStore.
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
#store ⇒ Object (readonly)
5 6 7 |
# File 'lib/lookbook/stores/tag_store.rb', line 5 def store @store end |
Class Method Details
.default_config ⇒ Object
30 31 32 |
# File 'lib/lookbook/stores/tag_store.rb', line 30 def self.default_config ConfigLoader.call(CONFIG_FILE) end |
.init_from_config ⇒ Object
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 |