Sha256: a80e27376a53efba319ea7b76b84e9d9dca061780080cdd9315a8bc2d487f07b

Contents?: true

Size: 616 Bytes

Versions: 25

Compression:

Stored size: 616 Bytes

Contents

require 'yaml/store'

module ThreeScaleToolbox
  class Configuration
    attr_reader :config_file

    def initialize(config_file)
      @config_file = config_file
      @store = YAML::Store.new(config_file)
    end

    def data(key)
      read[key]
    end

    def update(key)
      return if key.nil?

      @store.transaction do
        @store[key] = yield @store[key]
      end
    end

    private

    # returns copy of data stored
    def read
      @store.transaction(true) do
        @store.roots.each_with_object({}) do |key, obj|
          obj[key] = @store[key]
        end
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
3scale_toolbox-1.0.1 lib/3scale_toolbox/configuration.rb
3scale_toolbox-1.0.0 lib/3scale_toolbox/configuration.rb
3scale_toolbox-0.20.0 lib/3scale_toolbox/configuration.rb
3scale_toolbox-0.19.3 lib/3scale_toolbox/configuration.rb
3scale_toolbox-0.19.2 lib/3scale_toolbox/configuration.rb
3scale_toolbox-0.19.1 lib/3scale_toolbox/configuration.rb
3scale_toolbox-0.19.0 lib/3scale_toolbox/configuration.rb
3scale_toolbox-0.18.3 lib/3scale_toolbox/configuration.rb
3scale_toolbox-0.18.2 lib/3scale_toolbox/configuration.rb
3scale_toolbox-0.18.0 lib/3scale_toolbox/configuration.rb
3scale_toolbox-0.17.1 lib/3scale_toolbox/configuration.rb
3scale_toolbox-0.17.0 lib/3scale_toolbox/configuration.rb
3scale_toolbox-0.16.0 lib/3scale_toolbox/configuration.rb
3scale_toolbox-0.15.0 lib/3scale_toolbox/configuration.rb
3scale_toolbox-0.14.0 lib/3scale_toolbox/configuration.rb
3scale_toolbox-0.13.0 lib/3scale_toolbox/configuration.rb
3scale_toolbox-0.12.4 lib/3scale_toolbox/configuration.rb
3scale_toolbox-0.12.3 lib/3scale_toolbox/configuration.rb
3scale_toolbox-0.12.2 lib/3scale_toolbox/configuration.rb
3scale_toolbox-0.11.0 lib/3scale_toolbox/configuration.rb