resources/rc_file.rb
# backwards compatibility with 'poise'-based version.
# Previously, the "variables" would get passed straight through to the template,
# while "options" was used for everything except bash/bat file types.
# This was an undocumented feature, but could be used anyway.
# The standard should be to use one property for everything for a consistent API,
# regardless of what type of file it is.
# However, to prevent breaking existing code using this cookbook, we'll merge
# variables into options, so that it works either way.
backwards compatibility with 'poise'-based version.
Previously, the "variables" would get passed straight through to the template,
while "options" was used for everything except bash/bat file types.
This was an undocumented feature, but could be used anyway.
The standard should be to use one property for everything for a consistent API,
regardless of what type of file it is.
However, to prevent breaking existing code using this cookbook, we'll merge
variables into options, so that it works either way.
backwards compatibility with ' poise ' - based version . Previously the " variables " would get passed straight through to the template while " options " was used for everything except bash / bat file types . This was an undocumented feature but could be used anyway . The standard should be to use one property for everything for a consistent API regardless of what type of file it is . However to prevent breaking existing code using this cookbook we ' ll merge variables into options so that it works either way .
def to_content(type, options)
  case type
  when :edn
    require 'edn'
    options.to_edn
  when :yaml
    options.to_hash.to_yaml
  when :java, :properties, :java_properties
    require 'java-properties'
    JavaProperties.generate(options)
  when :toml
    require 'toml'
    TOML::Generator.new(options).body
  when :json
    JSON.pretty_generate(options)
  when :ini
    require 'iniparse'
    IniParse.gen do |doc|
      options.each_pair do |key, value|
        if value.kind_of?(Hash) 
          doc.section(key) do |s|
            value.each { |k, v| s.option(k, v) }
          end
        else
          doc.option(key, value)
        end
      end
    end.to_ini
  else
    options.to_hash
  end
end
def to_content ( type , options ) case type when :edn require 'edn' options . to_edn when :yaml options . to_hash . to_yaml when :java , :properties , :java_properties require 'java-properties' JavaProperties . generate ( options ) when :toml require 'toml' TOML :: Generator . new ( options ) . body when :json JSON . pretty_generate ( options ) when :ini require 'iniparse' IniParse . gen do | doc | options . each_pair do | key , value | if value . kind_of? ( Hash ) doc . section ( key ) do | s | value . each { | k , v | s . option ( k , v ) } end else doc . option ( key , value ) end end end . to_ini else options . to_hash end end
backwards compatibility with 'poise'-based version.
backwards compatibility with ' poise ' - based version .
# rubocop:disable Style/ClassCheck
type
options