Sha256: b9421746b88875930284cd99383c0841d32b4f2f2e4f5078941272d389e71c44

Contents?: true

Size: 1.64 KB

Versions: 17

Compression:

Stored size: 1.64 KB

Contents

module Nucleon
class Config
class Options
  
  #-----------------------------------------------------------------------------
  # Property accessors / modifiers
  
  @@options = {}
  
  #---
  
  def self.contexts(contexts = [], hierarchy = [])
    contexts = [ 'all', contexts ].flatten
    
    unless hierarchy.is_a?(Array)
      hierarchy = ( ! Util::Data.empty?(hierarchy) ? [ hierarchy ].flatten : [] )
    end
    
    hierarchy.each do |group|  
      group_contexts = Util::Data.prefix(group, contexts)
      contexts       = [ contexts, group_contexts ].flatten
    end
    
    return contexts
  end
  
  #---
  
  def self.all
    @@options
  end
  
  #---
  
  def self.get(contexts, force = true)
    options = {}
    
    unless contexts.is_a?(Array)
      contexts = ( ! Util::Data.empty?(contexts) ? [ contexts ].flatten : [] )
    end
    contexts.each do |name|
      name = name.to_sym
      if @@options.has_key?(name)
        options = Util::Data.merge([ options, @@options[name] ], force)
      end
    end
    return options
  end
  
  #---
  
  def self.set(contexts, options, force = true)
    unless contexts.is_a?(Array)
      contexts = ( ! Util::Data.empty?(contexts) ? [ contexts ].flatten : [] )
    end
    contexts.each do |name|
      name = name.to_sym    
      current_options = ( @@options.has_key?(name) ? @@options[name] : {} )
      @@options[name] = Util::Data.merge([ current_options, Config.symbol_map(options) ], force)
    end  
  end
  
  #---
  
  def self.clear(contexts)
    unless contexts.is_a?(Array)
      contexts = [ contexts ]
    end
    contexts.each do |name|
      @@options.delete(name.to_sym)
    end
  end
end
end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
nucleon-0.2.2 lib/core/config/options.rb
nucleon-0.2.1 lib/core/config/options.rb
nucleon-0.2.0 lib/core/config/options.rb
nucleon-0.1.19 lib/core/config/options.rb
nucleon-0.1.18 lib/core/config/options.rb
nucleon-0.1.17 lib/core/config/options.rb
nucleon-0.1.16 lib/core/config/options.rb
nucleon-0.1.15 lib/core/config/options.rb
nucleon-0.1.14 lib/core/config/options.rb
nucleon-0.1.13 lib/core/config/options.rb
nucleon-0.1.12 lib/core/config/options.rb
nucleon-0.1.11 lib/core/config/options.rb
nucleon-0.1.10 lib/core/config/options.rb
nucleon-0.1.9 lib/core/config/options.rb
nucleon-0.1.8 lib/core/config/options.rb
nucleon-0.1.7 lib/core/config/options.rb
nucleon-0.1.6 lib/core/config/options.rb