Class: SpigitConf::Engage

Inherits:
Object
  • Object
show all
Defined in:
lib/spigit_conf/engage.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Engage

Returns a new instance of Engage.



78
79
80
81
82
# File 'lib/spigit_conf/engage.rb', line 78

def initialize(opts = {})
  @file = opts.fetch(:file)
  @doc = Nokogiri::XML(File.read(@file)) { |x| x.noblanks }
  @spigit_config = @doc.at_css('spigit-config')
end

Instance Attribute Details

#docObject (readonly)

Returns the value of attribute doc.



76
77
78
# File 'lib/spigit_conf/engage.rb', line 76

def doc
  @doc
end

#fileObject (readonly)

Returns the value of attribute file.



76
77
78
# File 'lib/spigit_conf/engage.rb', line 76

def file
  @file
end

#spigit_configObject (readonly)

Returns the value of attribute spigit_config.



76
77
78
# File 'lib/spigit_conf/engage.rb', line 76

def spigit_config
  @spigit_config
end

Instance Method Details

#save!(opts = {}) ⇒ Object



84
85
86
87
88
89
90
91
# File 'lib/spigit_conf/engage.rb', line 84

def save!(opts = {})
  backup = opts.fetch(:backup, true)
  take_backup if backup

  File.open(file, 'w') do |f|
    f.write(doc.to_xml(save_with: SpigitConf::XML_SAVE_OPTIONS, :indent => 4, :encoding => 'UTF-8'))
  end
end