Class: XMigra::SchemaManipulator

Inherits:
Object
  • Object
show all
Defined in:
lib/xmigra/schema_manipulator.rb

Constant Summary collapse

DBINFO_FILE =
'database.yaml'
PERMISSIONS_FILE =
'permissions.yaml'
ACCESS_SUBDIR =
'access'
INDEXES_SUBDIR =
'indexes'
STRUCTURE_SUBDIR =
'structure'
VERINC_FILE =
'branch-upgrade.yaml'
PLUGIN_KEY =
'XMigra plugin'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ SchemaManipulator

Returns a new instance of SchemaManipulator.

Raises:

  • (TypeError)


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/xmigra/schema_manipulator.rb', line 13

def initialize(path)
  @path = Pathname.new(path)
  @db_info = YAML.load_file(@path + DBINFO_FILE)
  raise TypeError, "Expected Hash in #{DBINFO_FILE}" unless Hash === @db_info
  @db_info = Hash.new do |h, k|
    raise Error, "#{DBINFO_FILE} missing key #{k.inspect}"
  end.update(@db_info)
  
  db_system = @db_info['system']
  extend(
    @db_specifics = DatabaseSupportModules.find {|m|
      m::SYSTEM_NAME == db_system
    } || NoSpecifics
  )
  
  extend(
    @vcs_specifics = VersionControlSupportModules.find {|m|
      m.manages(path)
    } || NoSpecifics
  )
  
  if @db_info.has_key? PLUGIN_KEY
    @plugin = @db_info[PLUGIN_KEY]
  end
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



39
40
41
# File 'lib/xmigra/schema_manipulator.rb', line 39

def path
  @path
end

#pluginObject (readonly)

Returns the value of attribute plugin.



39
40
41
# File 'lib/xmigra/schema_manipulator.rb', line 39

def plugin
  @plugin
end

Instance Method Details

#branch_upgrade_fileObject



41
42
43
# File 'lib/xmigra/schema_manipulator.rb', line 41

def branch_upgrade_file
  @path.join(STRUCTURE_SUBDIR, VERINC_FILE)
end

#load_plugin!Object



45
46
47
# File 'lib/xmigra/schema_manipulator.rb', line 45

def load_plugin!
  Plugin.load! plugin if plugin
end