Class: Dist::Configuration

Inherits:
Object
  • Object
show all
Includes:
Error
Defined in:
lib/dist/configuration.rb

Defined Under Namespace

Classes: Property, Section

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Error

#error, #error_at

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



9
10
11
12
13
14
15
16
17
18
# File 'lib/dist/configuration.rb', line 9

def initialize
  @vars = {}
  @dependencies = []
  @sections = []
  @after_install_commands = []
  @before_build_commands = []

  config_contents = File.read("config/dist.rb") rescue error("config/dist.rb file not found. Please run `dist init`.")
  instance_eval config_contents
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



50
51
52
53
54
55
# File 'lib/dist/configuration.rb', line 50

def method_missing(name, *args)
  if args.empty? && value = @vars[name]
    return value
  end
  super
end

Instance Attribute Details

#after_install_commandsObject (readonly)

Returns the value of attribute after_install_commands.



6
7
8
# File 'lib/dist/configuration.rb', line 6

def after_install_commands
  @after_install_commands
end

#before_build_commandsObject (readonly)

Returns the value of attribute before_build_commands.



7
8
9
# File 'lib/dist/configuration.rb', line 7

def before_build_commands
  @before_build_commands
end

#dependenciesObject (readonly)

Returns the value of attribute dependencies.



4
5
6
# File 'lib/dist/configuration.rb', line 4

def dependencies
  @dependencies
end

#sectionsObject (readonly)

Returns the value of attribute sections.



5
6
7
# File 'lib/dist/configuration.rb', line 5

def sections
  @sections
end

Instance Method Details

#after_install(command) ⇒ Object



42
43
44
# File 'lib/dist/configuration.rb', line 42

def after_install(command)
  @after_install_commands << command
end

#before_build(command) ⇒ Object



46
47
48
# File 'lib/dist/configuration.rb', line 46

def before_build(command)
  @before_build_commands << command
end

#config(section, &block) ⇒ Object



36
37
38
39
40
# File 'lib/dist/configuration.rb', line 36

def config(section, &block)
  config_section = Section.new(section)
  config_section.instance_eval &block
  @sections << config_section
end

#get(name) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/dist/configuration.rb', line 24

def get(name)
  if @vars.has_key?(name)
    @vars[name]
  else
    error "missing setting '#{name}'"
  end
end

#set(name, value) ⇒ Object



20
21
22
# File 'lib/dist/configuration.rb', line 20

def set(name, value)
  @vars[name] = value
end

#use(service) ⇒ Object



32
33
34
# File 'lib/dist/configuration.rb', line 32

def use(service)
  @dependencies << service
end