Class: Monark::Context
- Inherits:
-
Object
- Object
- Monark::Context
- Defined in:
- lib/monark/context.rb
Overview
Monark runtime. Encapsulates state and manages migrations.
Instance Attribute Summary collapse
-
#connection ⇒ Object
Returns the value of attribute connection.
- #env ⇒ Object
- #manifest ⇒ Object
-
#migrations ⇒ Object
readonly
Returns the value of attribute migrations.
-
#migrations_file_name ⇒ Object
Returns the value of attribute migrations_file_name.
-
#root ⇒ Object
Returns the value of attribute root.
-
#version ⇒ Object
Returns the value of attribute version.
Instance Method Summary collapse
- #assume_done ⇒ Object
- #done ⇒ Object
-
#initialize(root, migrations_file_name = Monark::DEFAULT_MIGRATIONS_FILE_NAME) ⇒ Context
constructor
A new instance of Context.
- #load_manifest ⇒ Object
- #migrate(options = {}) ⇒ Object
- #push(*args) ⇒ Object
Constructor Details
#initialize(root, migrations_file_name = Monark::DEFAULT_MIGRATIONS_FILE_NAME) ⇒ Context
Returns a new instance of Context.
10 11 12 13 14 |
# File 'lib/monark/context.rb', line 10 def initialize(root, migrations_file_name = Monark::DEFAULT_MIGRATIONS_FILE_NAME) self.root = Pathname.new(root) self.migrations_file_name = migrations_file_name @migrations = [] end |
Instance Attribute Details
#connection ⇒ Object
Returns the value of attribute connection.
5 6 7 |
# File 'lib/monark/context.rb', line 5 def connection @connection end |
#env ⇒ Object
16 17 18 |
# File 'lib/monark/context.rb', line 16 def env defined?(@env) ? @env : Monark.env end |
#manifest ⇒ Object
20 21 22 |
# File 'lib/monark/context.rb', line 20 def manifest @manifest ||= root.join(migrations_file_name).read end |
#migrations ⇒ Object (readonly)
Returns the value of attribute migrations.
6 7 8 |
# File 'lib/monark/context.rb', line 6 def migrations @migrations end |
#migrations_file_name ⇒ Object
Returns the value of attribute migrations_file_name.
5 6 7 |
# File 'lib/monark/context.rb', line 5 def migrations_file_name @migrations_file_name end |
#root ⇒ Object
Returns the value of attribute root.
5 6 7 |
# File 'lib/monark/context.rb', line 5 def root @root end |
#version ⇒ Object
Returns the value of attribute version.
6 7 8 |
# File 'lib/monark/context.rb', line 6 def version @version end |
Instance Method Details
#assume_done ⇒ Object
46 47 48 49 50 |
# File 'lib/monark/context.rb', line 46 def assume_done load_manifest schema = Schema.new schema.next_migration = migrations.count end |
#done ⇒ Object
39 40 41 42 43 44 |
# File 'lib/monark/context.rb', line 39 def done load_manifest count = migrations.count schema = Schema.new schema.next_migration = count if count > schema.next_migration end |
#load_manifest ⇒ Object
28 29 30 31 32 33 |
# File 'lib/monark/context.rb', line 28 def load_manifest @loaded_manifest ||= begin DSL.new(self).instance_eval(manifest, root.join(migrations_file_name).to_s, 0) true end end |
#migrate(options = {}) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/monark/context.rb', line 52 def migrate( = {}) load_manifest schema = Schema.new ActiveRecord::Base.transaction do migrations.each_with_index do |migration, index| if (index >= schema.next_migration) || (migration.reloadable? && [:reload]) migration.perform end end done end end |
#push(*args) ⇒ Object
35 36 37 |
# File 'lib/monark/context.rb', line 35 def push(*args) migrations.push(*args) end |