Class: Aaron::Aaron

Inherits:
Object
  • Object
show all
Defined in:
lib/aaron.rb

Constant Summary collapse

@@possible_config_file_locations =
%w[
  ~/aaron.rb
].map { |f| File.expand_path(f) }

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, file = nil) ⇒ Aaron

Returns a new instance of Aaron.



43
44
45
46
# File 'lib/aaron.rb', line 43

def initialize config, file = nil
  @config = config
  @file   = file
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



16
17
18
# File 'lib/aaron.rb', line 16

def config
  @config
end

#fileObject (readonly)

Returns the value of attribute file.



16
17
18
# File 'lib/aaron.rb', line 16

def file
  @file
end

Class Method Details

.from_file(file) ⇒ Object



39
40
41
# File 'lib/aaron.rb', line 39

def self.from_file file
  Aaron.new(File.read(file), file)
end

.locate_config_fileObject



22
23
24
# File 'lib/aaron.rb', line 22

def self.locate_config_file
  @@possible_config_file_locations.find { |p| File.exists?(p) }
end

.runObject



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/aaron.rb', line 26

def self.run
  config_file = Aaron.locate_config_file
  if config_file
    Aaron.from_file(config_file).run
  else
    raise Errors::ConfigFileNotFound.new %Q(
      Aaron was unable to locate his config file.
      He looked in
      #{@@possible_config_file_locations.join("\n")}
    )
  end
end

Instance Method Details

#get_bindingObject



48
49
50
# File 'lib/aaron.rb', line 48

def get_binding
  DSL.new.instance_eval { binding }
end

#runObject



52
53
54
# File 'lib/aaron.rb', line 52

def run
  eval(config, get_binding, file).run
end