Sha256: 9efd1043247d5fdf8b8372757228533308348d4f869fc23aaf9fe97bf7f15da0

Contents?: true

Size: 960 Bytes

Versions: 23

Compression:

Stored size: 960 Bytes

Contents

module Lookbook
  class TagStore
    CONFIG_FILE = "config/tags.yml"

    attr_reader :store
    delegate :to_h, to: :store

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

    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

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

    def self.init_from_config
      new(default_config)
    end

    def self.default_config
      ConfigLoader.call(CONFIG_FILE)
    end

    protected

    def build_config(name, opts = nil, is_system = false)
      Store.new({
        name: name.to_sym,
        label: name.to_s.titleize,
        options: opts.to_h,
        system: is_system
      })
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
lookbook-2.3.4 lib/lookbook/stores/tag_store.rb
lookbook-2.3.3 lib/lookbook/stores/tag_store.rb
lookbook-2.3.2 lib/lookbook/stores/tag_store.rb
lookbook-2.3.0 lib/lookbook/stores/tag_store.rb
lookbook-2.2.2 lib/lookbook/stores/tag_store.rb
lookbook-2.2.1 lib/lookbook/stores/tag_store.rb
lookbook-2.2.0 lib/lookbook/stores/tag_store.rb
lookbook-2.1.1 lib/lookbook/stores/tag_store.rb
lookbook-2.1.0 lib/lookbook/stores/tag_store.rb
lookbook-2.0.5 lib/lookbook/stores/tag_store.rb
lookbook-2.0.4 lib/lookbook/stores/tag_store.rb
lookbook-2.0.3 lib/lookbook/stores/tag_store.rb
lookbook-2.0.2 lib/lookbook/stores/tag_store.rb
lookbook-2.0.1 lib/lookbook/stores/tag_store.rb
lookbook-2.0.0 lib/lookbook/stores/tag_store.rb
lookbook-2.0.0.rc.3 lib/lookbook/stores/tag_store.rb
lookbook-2.0.0.rc.2 lib/lookbook/stores/tag_store.rb
lookbook-2.0.0.rc.1 lib/lookbook/stores/tag_store.rb
lookbook-2.0.0.beta.9 lib/lookbook/stores/tag_store.rb
lookbook-2.0.0.beta.8 lib/lookbook/stores/tag_store.rb