Module: AppConfig::Processor

Included in:
AppConfig
Defined in:
lib/app-config/processor.rb

Instance Method Summary collapse

Instance Method Details

#process(data, type) ⇒ Object

Process data value for the format

Raises:



33
34
35
36
# File 'lib/app-config/processor.rb', line 33

def process(data, type)
  raise InvalidType, 'Type is invalid!' unless FORMATS.include?(type)
  send("process_#{type}".to_sym, data.to_s)
end

#process_array(value) ⇒ Object

Process array of strings



9
10
11
# File 'lib/app-config/processor.rb', line 9

def process_array(value)
  value.split("\n").map { |s| s.to_s.strip }.compact.select { |s| !s.empty? }
end

#process_boolean(value) ⇒ Object

Parse boolean string



14
15
16
# File 'lib/app-config/processor.rb', line 14

def process_boolean(value)
  ['true', 'on', 'yes', 'y', '1'].include?(value.to_s.downcase)
end

#process_hash(value) ⇒ Object

Parse hash string value should be in the following format: “keyname: value, key2: value2”



21
22
23
24
25
26
27
28
29
30
# File 'lib/app-config/processor.rb', line 21

def process_hash(value)
  result = {}
  unless value.empty?
    value.split(",").each do |s|
      k,v = s.split(':').compact.map { |i| i.to_s.strip }
      result[k] = v.to_s
    end
  end
  result
end

#process_string(value) ⇒ Object

Process string value



4
5
6
# File 'lib/app-config/processor.rb', line 4

def process_string(value)
  value.strip
end