Class: Turntables::Repository

Inherits:
Object
  • Object
show all
Includes:
RepositoryConstants
Defined in:
lib/turntables/repository.rb

Overview

and comments about said transaction).

Constant Summary

Constants included from RepositoryConstants

Turntables::RepositoryConstants::MonoDir, Turntables::RepositoryConstants::SeqDir

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRepository

Returns a new instance of Repository.



20
21
22
23
# File 'lib/turntables/repository.rb', line 20

def initialize
  @transactions = Array.new
  @monolithics  = Array.new
end

Instance Attribute Details

#monolithic_dirObject

Returns the value of attribute monolithic_dir.



60
61
62
# File 'lib/turntables/repository.rb', line 60

def monolithic_dir
  @monolithic_dir
end

#monolithicsObject

Array<Turntables::Transaction>



65
66
67
# File 'lib/turntables/repository.rb', line 65

def monolithics
  @monolithics
end

#relative_dirObject

Returns the value of attribute relative_dir.



61
62
63
# File 'lib/turntables/repository.rb', line 61

def relative_dir
  @relative_dir
end

#sequential_dirObject

Returns the value of attribute sequential_dir.



59
60
61
# File 'lib/turntables/repository.rb', line 59

def sequential_dir
  @sequential_dir
end

#transactionsObject

Array<Turntables::Transaction>



63
64
65
# File 'lib/turntables/repository.rb', line 63

def transactions
  @transactions
end

Instance Method Details

#make!Object

Function to call in order to make the database.

TODO: Here, it should detect in what state the current database is in, and go from there. In other words, whether it can skip sequential database transactions by loading a monolithic one to exclude previous transactions.



42
43
44
45
46
47
48
49
# File 'lib/turntables/repository.rb', line 42

def make!
  select_transactions!
  @transactions.each do |transaction| 
    vh = VersionHistory.new(transaction.version, transaction.comment)
    VersionHistory.insert(vh)
    DbRegistry.instance.execute_batch(transaction.data)
  end
end

#malformed?Boolean

Check to see if the directory structure is malformed.

Returns:

  • (Boolean)

    true if the directory structure is malformed



53
54
55
56
57
# File 'lib/turntables/repository.rb', line 53

def malformed?
  abs_seq = File.expand_path(@sequential_dir)
  abs_mon = File.expand_path(@monolithic_dir)
  !(File.exists?(abs_seq) && File.exists?(abs_mon))
end

#register(location) ⇒ Object

Parameters:

  • location

    is the location of the sql repository for now (a directory for now).



27
28
29
30
31
32
33
34
35
# File 'lib/turntables/repository.rb', line 27

def register(location)
  @relative_dir = location
  @sequential_dir = "#{@relative_dir}/#{SeqDir}/"
  @monolithic_dir = "#{@relative_dir}/#{MonoDir}/"

  # Initialize the transactions
  init_sequential_transactions!
  init_monolithic_transactions!
end