Class: Veewee::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/veewee/config.rb,
lib/veewee/config/veewee.rb,
lib/veewee/config/component.rb,
lib/veewee/config/collection.rb,
lib/veewee/config/definition.rb

Defined Under Namespace

Classes: Collection, Component, Definition, Veewee

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Config

Returns a new instance of Config.



12
13
14
15
16
17
18
# File 'lib/veewee/config.rb', line 12

def initialize(options)
  @env = options[:env]

  # Initialize with defaults
  @veewee = ::Veewee::Config::Veewee.new(self)

end

Instance Attribute Details

#envObject (readonly)

Returns the value of attribute env.



10
11
12
# File 'lib/veewee/config.rb', line 10

def env
  @env
end

#veeweeObject

Returns the value of attribute veewee.



9
10
11
# File 'lib/veewee/config.rb', line 9

def veewee
  @veewee
end

Instance Method Details

#define {|config| ... } ⇒ Object

Yields:

  • (config)


20
21
22
23
24
25
26
27
28
29
# File 'lib/veewee/config.rb', line 20

def define()
  config = OpenStruct.new

  # Expose the veewee config
  config.veewee = @veewee

  # Process config file
  yield config

end

#load_veewee_configObject

We put a long name to not clash with any function in the Veewee file itself



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/veewee/config.rb', line 32

def load_veewee_config()
  veewee_configurator = self
  begin
    filename = File.join(Dir.pwd, "Veeweefile")
    if File.exists?(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