Sha256: ac49e7f7302d195eadd5f9901b5add6bfbb163f202959cc363aafbe2b2fbb953

Contents?: true

Size: 766 Bytes

Versions: 75

Compression:

Stored size: 766 Bytes

Contents

# frozen_string_literal: true

require "yaml"

module PlutoniumGenerators
  module Concerns
    module Config
      def write_config(scope, **kwargs)
        write_config! config.deep_merge({scope => kwargs})
      end

      def read_config(scope, key, default: nil)
        config.dig(scope, key) || default
      end

      private

      def config
        in_root do
          if File.exist? config_filename
            YAML.load_file(config_filename, permitted_classes: [Regexp, Symbol]) || {}
          else
            {}
          end
        end
      end

      def write_config!(config)
        in_root do
          File.write(config_filename, YAML.dump(config))
        end
      end

      def config_filename
        ".pu"
      end
    end
  end
end

Version data entries

75 entries across 75 versions & 1 rubygems

Version Path
plutonium-0.16.3 lib/generators/pu/lib/plutonium_generators/concerns/config.rb
plutonium-0.16.1 lib/generators/pu/lib/plutonium_generators/concerns/config.rb
plutonium-0.16.0 lib/generators/pu/lib/plutonium_generators/concerns/config.rb
plutonium-0.15.24 lib/generators/pu/lib/plutonium_generators/concerns/config.rb
plutonium-0.15.23 lib/generators/pu/lib/plutonium_generators/concerns/config.rb
plutonium-0.15.22 lib/generators/pu/lib/plutonium_generators/concerns/config.rb
plutonium-0.15.21 lib/generators/pu/lib/plutonium_generators/concerns/config.rb
plutonium-0.15.20 lib/generators/pu/lib/plutonium_generators/concerns/config.rb
plutonium-0.15.19 lib/generators/pu/lib/plutonium_generators/concerns/config.rb
plutonium-0.15.18 lib/generators/pu/lib/plutonium_generators/concerns/config.rb
plutonium-0.15.17 lib/generators/pu/lib/plutonium_generators/concerns/config.rb
plutonium-0.15.16 lib/generators/pu/lib/plutonium_generators/concerns/config.rb
plutonium-0.15.15 lib/generators/pu/lib/plutonium_generators/concerns/config.rb
plutonium-0.15.14 lib/generators/pu/lib/plutonium_generators/concerns/config.rb
plutonium-0.15.13 lib/generators/pu/lib/plutonium_generators/concerns/config.rb
plutonium-0.15.12 lib/generators/pu/lib/plutonium_generators/concerns/config.rb
plutonium-0.15.11 lib/generators/pu/lib/plutonium_generators/concerns/config.rb
plutonium-0.15.10 lib/generators/pu/lib/plutonium_generators/concerns/config.rb
plutonium-0.15.9 lib/generators/pu/lib/plutonium_generators/concerns/config.rb
plutonium-0.15.8 lib/generators/pu/lib/plutonium_generators/concerns/config.rb