Class: AngularConfig::Source

Inherits:
Object
  • Object
show all
Defined in:
lib/angular_config/source.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content) ⇒ Source

Returns a new instance of Source.



5
6
7
# File 'lib/angular_config/source.rb', line 5

def initialize(content)
  @content = content
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



3
4
5
# File 'lib/angular_config/source.rb', line 3

def content
  @content
end

Class Method Details

.load(path) ⇒ Object



25
26
27
# File 'lib/angular_config/source.rb', line 25

def self.load(path)
  AngularConfig::Source.new AngularConfig::File.new(path).content
end

.save(data, path) ⇒ Object



29
30
31
# File 'lib/angular_config/source.rb', line 29

def self.save(data, path)
  AngularConfig::File.new(path).content = data
end

Instance Method Details

#md5Object



9
10
11
# File 'lib/angular_config/source.rb', line 9

def md5
  Digest::MD5.hexdigest(content)
end

#resolve(hashed_keys) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/angular_config/source.rb', line 13

def resolve(hashed_keys)
  hashed_keys.content.each do |key, value|
    if value.is_a?(String)
      self.content.gsub!(key, value)
    else
      self.content.gsub!("\"#{key}\"", value.to_json)
    end
  end

  self
end