Class: DatabasePatcher::PatchEntity

Inherits:
Object
  • Object
show all
Defined in:
lib/database_patcher/patch_entity.rb

Direct Known Subclasses

File, Folder

Defined Under Namespace

Classes: File, Folder

Constant Summary collapse

UUID_MATCHER =
'[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, interface) ⇒ PatchEntity

Returns a new instance of PatchEntity.



16
17
18
19
# File 'lib/database_patcher/patch_entity.rb', line 16

def initialize(path, interface)
  @path = path
  @interface = interface
end

Instance Attribute Details

#interfaceObject (readonly)

Returns the value of attribute interface.



15
16
17
# File 'lib/database_patcher/patch_entity.rb', line 15

def interface
  @interface
end

#pathObject (readonly)

Returns the value of attribute path.



15
16
17
# File 'lib/database_patcher/patch_entity.rb', line 15

def path
  @path
end

Class Method Details

.factory(path, interface) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/database_patcher/patch_entity.rb', line 7

def self.factory(path, interface)
  if ::File.directory?(path)
    self::Folder.new(path, interface)
  else
    self::File.new(path, interface)
  end
end

Instance Method Details

#down(_connection) ⇒ Object



35
36
37
# File 'lib/database_patcher/patch_entity.rb', line 35

def down(_connection)
  raise
end

#timestampObject



21
22
23
# File 'lib/database_patcher/patch_entity.rb', line 21

def timestamp
  basename.scan(/^\d+/).flatten.first.to_i
end

#uniq_indentifierObject



39
40
41
42
43
44
# File 'lib/database_patcher/patch_entity.rb', line 39

def uniq_indentifier
  {
    timestamp: timestamp,
    uuid: uuid
  }
end

#up(_connection) ⇒ Object



31
32
33
# File 'lib/database_patcher/patch_entity.rb', line 31

def up(_connection)
  raise
end

#uuidObject



26
27
28
29
# File 'lib/database_patcher/patch_entity.rb', line 26

def uuid
  basename = ::File.basename(@path, '.*')
  basename.scan(/^\d+_(#{UUID_MATCHER})_/).flatten.first.to_s
end