Class: Molecule::Registry
- Inherits:
-
Object
- Object
- Molecule::Registry
- Defined in:
- lib/molecule/registry.rb
Instance Attribute Summary collapse
-
#molecules ⇒ Object
Returns the value of attribute molecules.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #dump_molecule_file ⇒ Object
-
#initialize(name) ⇒ Registry
constructor
A new instance of Registry.
- #molecule_structure ⇒ Object
- #open_molecule_file ⇒ Object
- #read_molecule_file ⇒ Object
- #register_molecule(molecule_name) ⇒ Object
- #registry_file_path ⇒ Object
Constructor Details
#initialize(name) ⇒ Registry
Returns a new instance of Registry.
10 11 12 13 |
# File 'lib/molecule/registry.rb', line 10 def initialize name @name = name @molecules = {} end |
Instance Attribute Details
#molecules ⇒ Object
Returns the value of attribute molecules.
8 9 10 |
# File 'lib/molecule/registry.rb', line 8 def molecules @molecules end |
#name ⇒ Object
Returns the value of attribute name.
8 9 10 |
# File 'lib/molecule/registry.rb', line 8 def name @name end |
Instance Method Details
#dump_molecule_file ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/molecule/registry.rb', line 20 def dump_molecule_file molecule = read_molecule_file || {} molecule[:dependencies] = @molecules.keys File.open(registry_file_path, 'w') do |file| file.write(molecule_structure.to_json) end end |
#molecule_structure ⇒ Object
42 43 44 45 46 |
# File 'lib/molecule/registry.rb', line 42 def molecule_structure { dependencies: @molecules.keys.to_json } end |
#open_molecule_file ⇒ Object
32 33 34 35 36 |
# File 'lib/molecule/registry.rb', line 32 def open_molecule_file File.read(registry_file_path) rescue '{}' end |
#read_molecule_file ⇒ Object
28 29 30 |
# File 'lib/molecule/registry.rb', line 28 def read_molecule_file JSON.parse(open_molecule_file, symbolize_names: true) end |
#register_molecule(molecule_name) ⇒ Object
15 16 17 18 |
# File 'lib/molecule/registry.rb', line 15 def register_molecule molecule_name @molecules[molecule_name] = 1 nil end |
#registry_file_path ⇒ Object
38 39 40 |
# File 'lib/molecule/registry.rb', line 38 def registry_file_path Rails.root.join('app', 'molecules', @name, 'Moleculefile') end |