Sha256: ac49e7f7302d195eadd5f9901b5add6bfbb163f202959cc363aafbe2b2fbb953

Contents?: true

Size: 766 Bytes

Versions: 69

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

69 entries across 69 versions & 1 rubygems

Version Path
plutonium-0.19.2 lib/generators/pu/lib/plutonium_generators/concerns/config.rb
plutonium-0.19.1 lib/generators/pu/lib/plutonium_generators/concerns/config.rb
plutonium-0.19.0 lib/generators/pu/lib/plutonium_generators/concerns/config.rb
plutonium-0.18.8 lib/generators/pu/lib/plutonium_generators/concerns/config.rb
plutonium-0.18.7 lib/generators/pu/lib/plutonium_generators/concerns/config.rb
plutonium-0.18.6 lib/generators/pu/lib/plutonium_generators/concerns/config.rb
plutonium-0.18.5 lib/generators/pu/lib/plutonium_generators/concerns/config.rb
plutonium-0.18.4 lib/generators/pu/lib/plutonium_generators/concerns/config.rb
plutonium-0.18.3 lib/generators/pu/lib/plutonium_generators/concerns/config.rb
plutonium-0.18.2 lib/generators/pu/lib/plutonium_generators/concerns/config.rb
plutonium-0.18.1 lib/generators/pu/lib/plutonium_generators/concerns/config.rb
plutonium-0.18.0 lib/generators/pu/lib/plutonium_generators/concerns/config.rb
plutonium-0.16.5 lib/generators/pu/lib/plutonium_generators/concerns/config.rb
plutonium-0.16.4 lib/generators/pu/lib/plutonium_generators/concerns/config.rb
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