class Sumodev::Sumofile

Attributes

variables[RW]

Public Class Methods

current_config() click to toggle source
# File lib/sumodev/sumofile.rb, line 18
def current_config
  data = File.read("#{temp_path}/sumofile.json")
  json = MultiJson.load data

  new do |sumofile|
    sumofile.variables = json['sumofile']
  end
rescue Errno::ENOENT
  raise NoSuchFileError
end
from_file(path) click to toggle source
# File lib/sumodev/sumofile.rb, line 7
def from_file(path)
  new do |sumofile|
    File.readlines(path).each do |line|
      _, name, value = line.match(/^(.+?)\s+['"]?(.+?)['"]?$/).to_a
      sumofile[name] = value
    end
  end
rescue Errno::ENOENT
  raise NoSuchFileError
end
new() { |self| ... } click to toggle source
# File lib/sumodev/sumofile.rb, line 34
def initialize
  @variables = {}

  yield self if block_given?
end
temp_path() click to toggle source
# File lib/sumodev/sumofile.rb, line 29
def temp_path
  File.expand_path(Sumodev::Config.get('SUMO_TEMP_PATH'));
end

Public Instance Methods

[](name)
Alias for: get
[]=(name, value) click to toggle source
# File lib/sumodev/sumofile.rb, line 51
def []=(name, value)
  @variables[name] = value
end
convert_into_json_file() click to toggle source
# File lib/sumodev/sumofile.rb, line 40
def convert_into_json_file
  File.open("#{self.class.temp_path}/sumofile.json", "w") do |file|
    file.write to_json
  end
end
get(name) click to toggle source
# File lib/sumodev/sumofile.rb, line 46
def get(name)
  @variables[name]
end
Also aliased as: []
to_json() click to toggle source
# File lib/sumodev/sumofile.rb, line 55
def to_json
  MultiJson.dump({'sumofile' => @variables})
end