Sha256: 3644410510562b34261b94eee3b7bf0d0b81120b5bdd4ba41cfd807ba076bc77

Contents?: true

Size: 1.28 KB

Versions: 1

Compression:

Stored size: 1.28 KB

Contents

$:.unshift(File.dirname(__FILE__)) unless $:.include?(File.dirname(__FILE__))
require 'yaml'
require 'ostruct'
require 'alias/manager'
require 'alias/creator'
require 'alias/constant_creator'
require 'alias/method_creator_helper'
require 'alias/instance_method_creator'
require 'alias/class_method_creator'
require 'alias/core_extensions'

module Alias
  extend self
  
  def load_config_file(file=nil)
    if file.nil?
      if File.exists?("config/aliases.yml")
        file = "config/aliases.yml"
      elsif File.exists?("aliases.yml")
        file = "aliases.yml"
      end
    end
    file ? YAML::load(File.read(file)) : {}
  end
  
  def init(options={})
    config_hash = load_config_file(options[:file])
    config.merge! config_hash
    config['verbose'] = options[:verbose] if !options[:verbose].nil?
    
    if block_given?
      obj = OpenStruct.new
      yield(obj)
      block_config = obj.to_hash.stringify_keys
      config.merge! block_config
    end
    
    manager.verbose = config['verbose'] if config.has_key?('verbose')
    config.each do |k,v|
      next if ['verbose'].include?(k)
      manager.create_aliases(k, v)
    end
    self
  end
  
  def config
    @config ||= {}
  end
  
  def config=(value); @config = value; end
    
  def manager
    @manager ||= Manager.new
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cldwalker-alias-0.1.1 lib/alias.rb