Sha256: 92d8a01d6f470e8f616b3fb839ce09d22d9b176bef7f4a23d515784d0f3422f6

Contents?: true

Size: 1.64 KB

Versions: 16

Compression:

Stored size: 1.64 KB

Contents

require 'veewee/config/veewee'
require 'veewee/config/collection'

require 'fileutils'

module Veewee
  class Config

    attr_accessor :veewee
    attr_reader :env

    def initialize(options)
      @env = options[:env]
      # Initialize with defaults
      @veewee = ::Veewee::Config::Veewee.new(self)
    end

    def define()
      config = OpenStruct.new

      # Expose the veewee config
      config.veewee = @veewee

      # Process config file
      yield config

    end

    # We put a long name to not clash with any function in the Veewee file itself
    def load_veewee_config()
      veewee_configurator = self
      begin
        filename = @env.config_filepath
        if File.exists?(filename)
          env.logger.info("Loading config file: #{filename}")
          veeweefile = File.read(filename)
          veeweefile["Veewee::Config.run"] = "veewee_configurator.define"
          #        http://www.dan-manges.com/blog/ruby-dsls-instance-eval-with-delegation
          instance_eval(veeweefile)
        else
          env.logger.info "No configfile found"
        end
      rescue LoadError => e
        env.ui.error "An error occurred"
        env.ui.error e.message
      rescue NoMethodError => e
        env.ui.error "Some method got an error in the configfile - Sorry"
        env.ui.error $!
        env.ui.error e.message
        raise Veewee::Error "Some method got an error in the configfile - Sorry"
      rescue Error => e
        env.ui.error "Error processing configfile - Sorry"
        env.ui.error e.message
        raise Veewee::Error "Error processing configfile - Sorry"
      end
      return self
    end

  end #End Class
end #End Module

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
veewee-0.5.0.alpha4 lib/veewee/config.rb
veewee-0.5.0.alpha3 lib/veewee/config.rb
veewee-0.5.0.alpha2 lib/veewee/config.rb
veewee-0.5.0.alpha1 lib/veewee/config.rb
veewee-0.4.5.1 lib/veewee/config.rb
veewee-0.4.5 lib/veewee/config.rb
veewee-0.4.5.pre1 lib/veewee/config.rb
veewee-0.4.4 lib/veewee/config.rb
veewee-0.4.3 lib/veewee/config.rb
veewee-0.4.2 lib/veewee/config.rb
veewee-0.4.1 lib/veewee/config.rb
veewee-0.4.0 lib/veewee/config.rb
veewee-0.3.12 lib/veewee/config.rb
veewee-0.3.11 lib/veewee/config.rb
veewee-0.3.10 lib/veewee/config.rb
veewee-0.3.9 lib/veewee/config.rb