Sha256: 8de22aaec8e25355387723008846b6a6da746c51607bf3713e3cfe056ea781c4

Contents?: true

Size: 1.68 KB

Versions: 4

Compression:

Stored size: 1.68 KB

Contents

module Nucleon
module Mixin
module Action
module Config

  #-----------------------------------------------------------------------------
  # Settings

  def config_config
    register_str :settings_path, CM.config_path, 'nucleon.mixin.action.config.options.settings_path' do |value|
      success = true

      if value
        path = File.expand_path(value)

        if File.exist?(path)
          success = false unless import_system_config(path)
        else
          warn('nucleon.mixin.action.config.errors.settings_path', { :path => path })
          success = false
        end
      end
      success
    end
  end

  #---

  def config_ignore
    [ :settings_path ]
  end

  #-----------------------------------------------------------------------------
  # Properties

  #-----------------------------------------------------------------------------
  # Utilities

  def import_system_config(path)
    config_provider = (File.directory?(path) ? :directory : :file)
    system_config = CM.configuration(extended_config(:system_config, {
      :path => path,
      :translator_error => 'nucleon.mixin.action.config.errors.translator',
      :config_error => 'nucleon.mixin.action.config.errors.config_file'
    }), config_provider).export

    unless system_config.nil?
      # Values are already set from parameters and validation is just starting
      system_config.each do |key, value|
        # TODO: Some error handling here if config key doesn't exist
        # For instance, if extra properties in config file
        if !config.has_key?(key) || settings[key] == config[key].default
          settings[key] = value
        end
      end
    end
    system_config.nil? ? false : true
  end
end
end
end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
cm-0.1.8 lib/core/mixin/action/config.rb
cm-0.1.6 lib/core/mixin/action/config.rb
cm-0.1.4 lib/core/mixin/action/config.rb
cm-0.1.3 lib/core/mixin/action/config.rb