class Confection::Store

Attributes

sources[R]

Public Class Methods

new(*sources) click to toggle source
# File lib/confection/store.rb, line 26
def initialize(*sources)
  @sources = sources

  @list = []

  sources.each do |source|
    if File.file?(source)
      parse(source)
    else
      # ignore directories
    end
  end
end

Public Instance Methods

<<(conf) click to toggle source

Add as configuratio to the store.

# File lib/confection/store.rb, line 67
def <<(conf)
  raise TypeError, "not a configuration instance -- `#{conf}'" unless Config === conf
  @list << conf
end
clear!() click to toggle source

Clear configs.

# File lib/confection/store.rb, line 112
def clear!
  @list = []
end
concat(configs) click to toggle source

Add a list of configs.

# File lib/confection/store.rb, line 75
def concat(configs)
  configs.each{ |c| self << c }
end
each(&block) click to toggle source

Iterate over each configurations.

# File lib/confection/store.rb, line 51
def each(&block)
  @list.each(&block)
end
first() click to toggle source
# File lib/confection/store.rb, line 117
def first
  @list.first
end
import(tool, profile, options, &block) click to toggle source

Import configuration from another project.

# File lib/confection/store.rb, line 140
def import(tool, profile, options, &block)
  from_tool    = options[:tool]    || tool
  from_profile = options[:profile] || profile

  case from = options[:from]
  when String, Symbol
    project = Project.load(from.to_s)
    store   = project ? project.store : nil
  else
    from  = '(self)'
    store = self
  end

  raise "no configuration found in `#{from}'" unless store

  configs = store.lookup(from_tool, from_profile)

  configs.each do |config|
    new_config = config.copy(:tool=>tool, :profile=>profile)

    #new_options = @_options.dup
    #new_options[:tool]    = tool
    #new_options[:profile] = profile
    #new_options[:block]   = config.block
    #new_options[:text]    = config.text

    # not so sure about this one
    if String === new_config.value
      new_config.value += ("\n" + options[:text].to_s) if options[:text]
    end

    self << new_config
  end

  #if block
  #  self << Config::Block.new(tool, profile, nil, &block)
  #end
end
last() click to toggle source
# File lib/confection/store.rb, line 122
def last
  @list.last
end
lookup(tool, profile=nil) click to toggle source

Lookup configuration by tool and profile name.

@todo Future versions should allow this to handle regex and fnmatches.

# File lib/confection/store.rb, line 84
def lookup(tool, profile=nil)
  if profile == '*'
    select do |c|
      c.tool.to_sym == tool.to_sym
    end
  else
    profile = profile.to_sym if profile

    select do |c|
      c.tool.to_sym == tool.to_sym && c.profile == profile
    end
  end
end
parse(file) click to toggle source
# File lib/confection/store.rb, line 44
def parse(file)
  DSL.parse(self, file)
end
profiles(tool) click to toggle source

Returns list of profiles collected from all configs.

# File lib/confection/store.rb, line 101
def profiles(tool)
  names = []
  each do |c|
    names << c.profile if c.tool == tool.to_sym
  end
  names.uniq
end
size() click to toggle source

The number of configurations.

@return [Fixnum] config count

# File lib/confection/store.rb, line 60
def size
  @list.size
end