Class: SwitchDb::ReferenceSet
- Inherits:
-
Object
- Object
- SwitchDb::ReferenceSet
- Defined in:
- lib/switch_db/reference_set.rb
Instance Attribute Summary collapse
-
#configuration_path ⇒ Object
readonly
Returns the value of attribute configuration_path.
-
#references ⇒ Object
readonly
Returns the value of attribute references.
Class Method Summary collapse
Instance Method Summary collapse
- #add_reference(reference) ⇒ Object
-
#initialize(configuration_path) ⇒ ReferenceSet
constructor
A new instance of ReferenceSet.
- #remove_reference(reference) ⇒ Object
- #write_reference_set ⇒ Object
Constructor Details
#initialize(configuration_path) ⇒ ReferenceSet
Returns a new instance of ReferenceSet.
8 9 10 11 |
# File 'lib/switch_db/reference_set.rb', line 8 def initialize(configuration_path) @configuration_path = configuration_path @references = {} end |
Instance Attribute Details
#configuration_path ⇒ Object (readonly)
Returns the value of attribute configuration_path.
6 7 8 |
# File 'lib/switch_db/reference_set.rb', line 6 def configuration_path @configuration_path end |
#references ⇒ Object (readonly)
Returns the value of attribute references.
6 7 8 |
# File 'lib/switch_db/reference_set.rb', line 6 def references @references end |
Class Method Details
.load_file(configuration_path) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/switch_db/reference_set.rb', line 13 def self.load_file(configuration_path) new(configuration_path).tap do |instance| yaml = YAML.load_file(configuration_path) (yaml[:references] || []).map do |reference| reference = Reference.new( name: reference[:name], database_names: reference[:database_names] ) instance.add_reference(reference) end end rescue Errno::ENOENT new(configuration_path) end |
Instance Method Details
#add_reference(reference) ⇒ Object
30 31 32 |
# File 'lib/switch_db/reference_set.rb', line 30 def add_reference(reference) @references[reference.name] = reference end |
#remove_reference(reference) ⇒ Object
34 35 36 |
# File 'lib/switch_db/reference_set.rb', line 34 def remove_reference(reference) @references.delete(reference.name) end |
#write_reference_set ⇒ Object
38 39 40 41 |
# File 'lib/switch_db/reference_set.rb', line 38 def write_reference_set FileUtils.mkdir_p(configuration_directory) File.write(@configuration_path, to_h.to_yaml) end |