Class: Molecule::File

Inherits:
Object
  • Object
show all
Defined in:
lib/molecule/file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ File

Returns a new instance of File.



8
9
10
# File 'lib/molecule/file.rb', line 8

def initialize name
  @name = name.to_s
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/molecule/file.rb', line 6

def name
  @name
end

Instance Method Details

#molecule_file_pathObject



22
23
24
# File 'lib/molecule/file.rb', line 22

def molecule_file_path
  Rails.root.join('app', 'molecules', @name, 'molecule.json').to_s
end

#readObject



12
13
14
# File 'lib/molecule/file.rb', line 12

def read
  JSON.parse(read_file, symbolize_names: true)
end

#read_fileObject



16
17
18
19
20
# File 'lib/molecule/file.rb', line 16

def read_file
  ::File.read(molecule_file_path)
rescue
  '{}'
end