Class: ConcurrentPipeline::Stores::Schema

Inherits:
Object
  • Object
show all
Defined in:
lib/concurrent_pipeline/stores/schema.rb

Defined Under Namespace

Classes: Migration, Record, RecordContext

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSchema



37
38
39
40
41
# File 'lib/concurrent_pipeline/stores/schema.rb', line 37

def initialize
  @migrations = []
  @records = {}
  @migration_counter = 1
end

Instance Attribute Details

#migrationsObject (readonly)

Returns the value of attribute migrations.



36
37
38
# File 'lib/concurrent_pipeline/stores/schema.rb', line 36

def migrations
  @migrations
end

#recordsObject (readonly)

Returns the value of attribute records.



36
37
38
# File 'lib/concurrent_pipeline/stores/schema.rb', line 36

def records
  @records
end

Instance Method Details

#dir(path = nil) ⇒ Object



43
44
45
46
# File 'lib/concurrent_pipeline/stores/schema.rb', line 43

def dir(path = nil)
  @dir = path if path
  @dir
end

#migrate(version = @migration_counter += 1, &block) ⇒ Object



48
49
50
# File 'lib/concurrent_pipeline/stores/schema.rb', line 48

def migrate(version = @migration_counter += 1, &block)
  migrations << Migration.new(version: version, block: block)
end

#prepend_migration(version, &block) ⇒ Object



52
53
54
# File 'lib/concurrent_pipeline/stores/schema.rb', line 52

def prepend_migration(version, &block)
  migrations.unshift(Migration.new(version: version, block: block))
end

#record(name, table: nil, &block) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/concurrent_pipeline/stores/schema.rb', line 56

def record(name, table: nil, &block)
  # If block is given, execute it in RecordContext to extract schema calls
  extracted_table = table
  if block
    context = RecordContext.new(self)
    context.instance_exec(&block)
    extracted_table ||= context.table_name
  end

  records[name] = Record.new(
    name: name,
    table: extracted_table,
    block: block
  )
end