Class: Dist::Configuration::Section

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Error

#error, #error_at

Constructor Details

#initialize(name) ⇒ Section

Returns a new instance of Section.



63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/dist/configuration.rb', line 63

def initialize(name)
  @name = name
  @properties = []

  @filename = "config/#{name}.yml"
  unless File.exists?(@filename)
    error_at "config :#{name}", "the file '#{@filename}' doesn't exist."
  end

  @yaml = YAML.load_file @filename
  @yaml = @yaml['production'] || @yaml
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



60
61
62
# File 'lib/dist/configuration.rb', line 60

def name
  @name
end

#propertiesObject (readonly)

Returns the value of attribute properties.



61
62
63
# File 'lib/dist/configuration.rb', line 61

def properties
  @properties
end

Instance Method Details

#add_property(name, type, options = {}) ⇒ Object



80
81
82
83
84
85
86
# File 'lib/dist/configuration.rb', line 80

def add_property(name, type, options = {})
  unless @yaml.has_key?(name.to_s)
    error_at "#{type}: :#{name}", "the property '#{name}' inside the file '#{@filename} doesn't exist."
  end

  @properties << Property.new(self, name, type, options)
end

#string(name, options = {}) ⇒ Object



76
77
78
# File 'lib/dist/configuration.rb', line 76

def string(name, options = {})
  add_property name, :string, options
end

#to_sObject



88
89
90
# File 'lib/dist/configuration.rb', line 88

def to_s
  name.to_s
end