Class: SwitchDb::Reference

Inherits:
Object
  • Object
show all
Defined in:
lib/switch_db/reference.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, database_names: []) ⇒ Reference

Returns a new instance of Reference.



5
6
7
8
# File 'lib/switch_db/reference.rb', line 5

def initialize(name:, database_names: [])
  @name = name
  @database_names = database_names
end

Instance Attribute Details

#database_namesObject (readonly)

Returns the value of attribute database_names.



3
4
5
# File 'lib/switch_db/reference.rb', line 3

def database_names
  @database_names
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/switch_db/reference.rb', line 3

def name
  @name
end

Instance Method Details

#database_pathsObject



18
19
20
21
22
# File 'lib/switch_db/reference.rb', line 18

def database_paths
  @database_names.map { |database_name|
    [database_name, full_path.join("#{Utils.escape_filename(database_name)}.sql")]
  }.to_h
end

#full_pathObject



14
15
16
# File 'lib/switch_db/reference.rb', line 14

def full_path
  SwitchDb.configuration.cache_dir.join(path)
end

#pathObject



10
11
12
# File 'lib/switch_db/reference.rb', line 10

def path
  Utils.escape_filename(@name)
end

#to_hObject



24
25
26
27
28
29
# File 'lib/switch_db/reference.rb', line 24

def to_h
  {
    name: name,
    database_names: database_names
  }
end