Sha256: 7e012add69a58b1dd958b53cc0cc0d0176733588b3637e7f2347b8eafcb118ee

Contents?: true

Size: 1.18 KB

Versions: 17

Compression:

Stored size: 1.18 KB

Contents

class BuildConfig
  @@app_config = nil
  @@config = nil
  @@shared_config = nil

  class << self

    def parse_path(path)
      path.split('/').map{|c| c.strip}.reject { |c| c.empty? }
    end

    def find_elem(config, path, default = nil)
      if path.kind_of?(String)
        loc_path = parse_path(path)
      else
        loc_path = path.dup
      end

      result = nil

      if !config.nil?
        result = config
        until result.nil? || loc_path.empty?
          section = loc_path.shift
          result = section.nil? ? nil : result[section]
        end
      end

      result.nil? ? default : result
    end

    def get_key(key_path, default = nil)
      if key_path.kind_of?(String)
        key_sections = parse_path(key_path)
      end

      result = nil

      [@@app_config, $app_config, @@config, $config, @@shared_config, $shared_config].compact.each do |config|
        unless config.nil?
          result = find_elem(config, key_sections, nil)

          break unless result.nil?
        end
      end

      puts "Could not get config #{key_path}" if result.nil?

      result.nil? ? default : result
    end

    attr_accessor :app_config, :config, :shared_config
  end


end

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
rhodes-7.6.0 lib/build/BuildConfig.rb
rhodes-7.5.1 lib/build/BuildConfig.rb
rhodes-7.4.1 lib/build/BuildConfig.rb
rhodes-7.1.17 lib/build/BuildConfig.rb
rhodes-6.2.0 lib/build/BuildConfig.rb
rhodes-6.0.11 lib/build/BuildConfig.rb
rhodes-5.5.18 lib/build/BuildConfig.rb
rhodes-5.5.17 lib/build/BuildConfig.rb
rhodes-5.5.15 lib/build/BuildConfig.rb
rhodes-5.5.0.22 lib/build/BuildConfig.rb
rhodes-5.5.2 lib/build/BuildConfig.rb
rhodes-5.5.0.7 lib/build/BuildConfig.rb
rhodes-5.5.0.3 lib/build/BuildConfig.rb
rhodes-5.5.0 lib/build/BuildConfig.rb
tauplatform-1.0.3 lib/build/BuildConfig.rb
tauplatform-1.0.2 lib/build/BuildConfig.rb
tauplatform-1.0.1 lib/build/BuildConfig.rb