Class: Molecule::Registry

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#moleculesObject

Returns the value of attribute molecules.



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

def molecules
  @molecules
end

#nameObject

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_fileObject



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_structureObject



42
43
44
45
46
# File 'lib/molecule/registry.rb', line 42

def molecule_structure
  {
    dependencies: @molecules.keys.to_json
  }
end

#open_molecule_fileObject



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_fileObject



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_pathObject



38
39
40
# File 'lib/molecule/registry.rb', line 38

def registry_file_path
  Rails.root.join('app', 'molecules', @name, 'Moleculefile')
end