Class: Konfig::Adapter
Overview
All adapters are subclassed from Konfig::Adapter
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
included
Constructor Details
#initialize(data) ⇒ Adapter
Returns a new instance of Adapter.
11
12
13
|
# File 'lib/konfig/adapter.rb', line 11
def initialize(data)
@data = data
end
|
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
9
10
11
|
# File 'lib/konfig/adapter.rb', line 9
def data
@data
end
|
Class Method Details
.adjust_whitespace(content) ⇒ Object
39
40
41
42
43
|
# File 'lib/konfig/adapter.rb', line 39
def adjust_whitespace(content)
content.gsub!(/\t/, " ")
adjustment = content.lines.map { |l| l =~ /^( *)\S+$/; $1 && $1.size }.compact.min
content.lines.map { |l| l =~ /^[ ]{#{ adjustment }}(.*)$/; $1.to_s }.join("\n")
end
|
.has_template(key, options = {}) ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/konfig/adapter.rb', line 17
def has_template(key, options = {})
if block_given?
content = yield
else
content = options[:file] && File.read(options[:file])
unless content
content = options[:content]
content = adjust_whitespace(content) unless options[:preserve_indentation]
end
end
Adapter.templates[key] = content
end
|
.template_for(key) ⇒ Object
31
32
33
|
# File 'lib/konfig/adapter.rb', line 31
def template_for(key)
Adapter.templates[key]
end
|
.templates ⇒ Object
35
36
37
|
# File 'lib/konfig/adapter.rb', line 35
def templates
@templates ||= HashWithIndifferentAccess.new
end
|