Class: Sumodev::Sumofile
- Inherits:
-
Object
- Object
- Sumodev::Sumofile
- Defined in:
- lib/sumodev/sumofile.rb
Defined Under Namespace
Classes: NoSuchFileError
Instance Attribute Summary collapse
-
#variables ⇒ Object
Returns the value of attribute variables.
Class Method Summary collapse
Instance Method Summary collapse
- #[]=(name, value) ⇒ Object
- #convert_into_json_file ⇒ Object
- #get(name) ⇒ Object (also: #[])
-
#initialize {|_self| ... } ⇒ Sumofile
constructor
A new instance of Sumofile.
- #to_json ⇒ Object
Constructor Details
#initialize {|_self| ... } ⇒ Sumofile
Returns a new instance of Sumofile.
34 35 36 37 38 |
# File 'lib/sumodev/sumofile.rb', line 34 def initialize @variables = {} yield self if block_given? end |
Instance Attribute Details
#variables ⇒ Object
Returns the value of attribute variables.
4 5 6 |
# File 'lib/sumodev/sumofile.rb', line 4 def variables @variables end |
Class Method Details
.current_config ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# 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) ⇒ Object
7 8 9 10 11 12 13 14 15 16 |
# 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 |
Instance Method Details
#[]=(name, value) ⇒ Object
51 52 53 |
# File 'lib/sumodev/sumofile.rb', line 51 def []=(name, value) @variables[name] = value end |
#convert_into_json_file ⇒ Object
40 41 42 43 44 |
# 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) ⇒ Object Also known as: []
46 47 48 |
# File 'lib/sumodev/sumofile.rb', line 46 def get(name) @variables[name] end |
#to_json ⇒ Object
55 56 57 |
# File 'lib/sumodev/sumofile.rb', line 55 def to_json MultiJson.dump({'sumofile' => @variables}) end |