Class: Mio::Migrations
- Inherits:
-
Object
show all
- Defined in:
- lib/mio/migrations.rb
Instance Method Summary
collapse
Constructor Details
#initialize(base_uri, username, password, verify_ssl, base_dir = './migrations') ⇒ Migrations
Returns a new instance of Migrations.
7
8
9
10
11
12
13
14
15
16
|
# File 'lib/mio/migrations.rb', line 7
def initialize base_uri, username, password, verify_ssl, base_dir='./migrations'
@mio = Mio.new do |m|
m.base_uri = base_uri
m.username = username
m.password = password
m.verify_ssl = verify_ssl
end
@base = File.expand_path(base_dir)
@migrations = Dir.glob( File.join(@base, '*.rb') ).sort
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_sym, *arguments, &block) ⇒ Object
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/mio/migrations.rb', line 55
def method_missing method_sym, *arguments, &block
mapped = Mio::Model.mappings[method_sym.to_s]
if mapped.nil?
super
else
conf = OpenStruct.new
yield conf
type_migration mapped, conf
end
end
|
Instance Method Details
#create_migration_file(desc) ⇒ Object
18
19
20
21
|
# File 'lib/mio/migrations.rb', line 18
def create_migration_file desc
File.join(@base,
"#{Time.now.strftime('%Y%m%d%H%M%S')}_#{desc.gsub(/\W/, '-')}.rb")
end
|
#has_run?(migration) ⇒ Boolean
31
32
33
|
# File 'lib/mio/migrations.rb', line 31
def has_run? migration
false
end
|
#load_migration(migration) ⇒ Object
35
36
37
|
# File 'lib/mio/migrations.rb', line 35
def load_migration migration
eval File.read(migration)
end
|
#migrate(desc, &block) ⇒ Object
Helper methods for within the migrations
40
41
42
43
44
45
|
# File 'lib/mio/migrations.rb', line 40
def migrate desc, &block
msg desc, 'starting'
block.call
msg desc, 'completed'
end
|
#respond_to?(method_sym, include_private = false) ⇒ Boolean
67
68
69
70
71
72
73
|
# File 'lib/mio/migrations.rb', line 67
def respond_to? method_sym, include_private=false
if Mio::Model.mappings[method_sym.to_s].nil?
super
else
true
end
end
|
#run_migrations ⇒ Object
23
24
25
26
27
28
29
|
# File 'lib/mio/migrations.rb', line 23
def run_migrations
@migrations.each do |migration|
unless has_run? migration
load_migration migration
end
end
end
|
#type_migration(klass, conf) ⇒ Object
47
48
49
50
51
52
53
|
# File 'lib/mio/migrations.rb', line 47
def type_migration klass, conf
if klass.nested?
get_it klass.new(@mio.client, conf)
else
do_it klass.new(@mio.client, conf)
end
end
|