Module: ConfigMe::Runner

Defined in:
lib/config-me/runner.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.definitionsObject

Returns the value of attribute definitions.



4
5
6
# File 'lib/config-me/runner.rb', line 4

def definitions
  @definitions
end

.namespaceObject

Returns the value of attribute namespace.



4
5
6
# File 'lib/config-me/runner.rb', line 4

def namespace
  @namespace
end

.optionsObject

Returns the value of attribute options.



4
5
6
# File 'lib/config-me/runner.rb', line 4

def options
  @options
end

Class Method Details

.case_and_apply_action!Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/config-me/runner.rb', line 11

def case_and_apply_action!
  case
    when reading? then set_current_namespace
    when writing?
      ConfigMe::Importer.from_definitions namespace, definitions
    when importing_from_hash?
      ConfigMe::Importer.from_hash namespace, options[:hash]
    when importing_from_yaml?
      ConfigMe::Importer.from_yaml namespace, options[:yaml]
    else
      raise ConfigMe::UnrecognizedError.new
  end
end

.importing_from_hash?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/config-me/runner.rb', line 57

def importing_from_hash?
  options.has_key?(:hash)
end

.importing_from_yaml?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/config-me/runner.rb', line 61

def importing_from_yaml?
  options.has_key?(:yaml)
end

.parse(namespace_or_options, &definitions) ⇒ Object



6
7
8
9
# File 'lib/config-me/runner.rb', line 6

def parse namespace_or_options, &definitions
  parse_execution_params! namespace_or_options, &definitions
  case_and_apply_action!
end

.parse_execution_params!(namespace_or_options, &definitions) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/config-me/runner.rb', line 29

def parse_execution_params! namespace_or_options, &definitions
  self.definitions = definitions

  case
    # ConfigMe.foo
    # ConfigMe(:development).foo
    when namespace_or_options.is_a?(Symbol) || namespace_or_options.is_a?(String)
      self.namespace = namespace_or_options.to_sym
      self.options   = {}

    # ConfigMe(:from_hash => { :foo => :bar })
    # ConfigMe(:namespace => :development)
    when namespace_or_options.is_a?(Hash)
      self.namespace = namespace_or_options.delete(:namespace) || ConfigMe::Defaults.namespace
      self.options   = namespace_or_options
    else
      raise ConfigMe::UnrecognizedError.new
  end
end

.reading?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/config-me/runner.rb', line 49

def reading?
  options.empty? && definitions.nil?
end

.set_current_namespaceObject



25
26
27
# File 'lib/config-me/runner.rb', line 25

def set_current_namespace
  ConfigMe::Base.current_namespace = namespace
end

.writing?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/config-me/runner.rb', line 53

def writing?
  options.empty? && !definitions.nil?
end