Class: DbAgile::Core::IO::DSL

Inherits:
Object
  • Object
show all
Includes:
Robustness
Defined in:
lib/dbagile/core/io/dsl.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Robustness

#has_database!, #valid_database_name!, #valid_database_uri!, #valid_schema_files!

Constructor Details

#initialize(repository = nil, database = nil, &block) ⇒ DSL

Creates a DSL instance



14
15
16
17
18
# File 'lib/dbagile/core/io/dsl.rb', line 14

def initialize(repository = nil, database = nil, &block)
  @repository = repository
  @current_database = database
  self.instance_eval(&block) unless block.nil?
end

Instance Attribute Details

#current_databaseObject (readonly)

The current Database instance



11
12
13
# File 'lib/dbagile/core/io/dsl.rb', line 11

def current_database
  @current_database
end

#repositoryObject (readonly)

The Repository instance passed at construction



8
9
10
# File 'lib/dbagile/core/io/dsl.rb', line 8

def repository
  @repository
end

Instance Method Details

#announced_schema(*files) ⇒ Object

Sets the announced schema files



41
42
43
44
# File 'lib/dbagile/core/io/dsl.rb', line 41

def announced_schema(*files)
  dsl_has_database!
  current_database.announced_files = valid_schema_files!(files)
end

#current_db(name) ⇒ Object

Sets the current database



59
60
61
62
# File 'lib/dbagile/core/io/dsl.rb', line 59

def current_db(name)
  dsl_has_repository!
  repository.current_db_name = name
end

#database(name, &block) ⇒ Object

Adds a database under a given name



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/dbagile/core/io/dsl.rb', line 21

def database(name, &block)
  valid_database_name!(name)
  created = with_database(Core::Database.new(name)){|cfg|
    self.instance_eval(&block)
    cfg
  }
  unless repository.nil?
    repository << created
  end
  created
end

#effective_schema(*files) ⇒ Object

Sets the effective schema files



47
48
49
50
# File 'lib/dbagile/core/io/dsl.rb', line 47

def effective_schema(*files)
  dsl_has_database!
  current_database.effective_files = valid_schema_files!(files)
end

#plug(*args) ⇒ Object

See Also:



53
54
55
56
# File 'lib/dbagile/core/io/dsl.rb', line 53

def plug(*args)
  dsl_has_database!
  current_database.plug(*args)
end

#uri(str) ⇒ Object

Sets the uri on the current database



34
35
36
37
38
# File 'lib/dbagile/core/io/dsl.rb', line 34

def uri(str)
  dsl_has_database!
  valid_database_uri!(str)
  current_database.uri = str
end