Module: Configuru::ConfigMethods

Defined in:
lib/configuru/config_methods.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



5
6
7
# File 'lib/configuru/config_methods.rb', line 5

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#configure(options = {}) {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



85
86
87
88
89
90
91
92
93
94
95
# File 'lib/configuru/config_methods.rb', line 85

def configure(options={})
  Hash(options).each_pair do |name,value|
    if name.to_sym == :options_source
      self.options_source = value
    else
      send("#{name.to_s}=",value)
    end
  end
  yield self if block_given?
  self
end

#is_lockedObject



80
81
82
83
# File 'lib/configuru/config_methods.rb', line 80

def is_locked
  @locked = false unless instance_variable_defined?(:@locked)
  @locked
end

#lock(flag = true) ⇒ Object

Instance methods



77
78
79
# File 'lib/configuru/config_methods.rb', line 77

def lock(flag=true)
  @locked = flag
end

#options_source=(value) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/configuru/config_methods.rb', line 96

def options_source=(value)
  sub_options = case value
    when Hash, Array then value
    when IO, StringIO, Tempfile then 
      YAML.load(value)
    when String, Pathname
      output = {}
      File.open(value,"r") { |f| output = YAML.load(f) }
      output
    else
      raise ArgumentError.new("Wrong argument class for options_source: #{value.class}")
  end
  if sub_options.is_a? Array
    sub_options.each { |elem| self.options_source=elem }
  else
    configure(sub_options)
  end
end