Class: CouchMigrate::BaseExecuter

Inherits:
Object
  • Object
show all
Defined in:
lib/couch_migrate/base_executer.rb

Direct Known Subclasses

CouchExecuter

Defined Under Namespace

Modules: Namespaced

Instance Method Summary collapse

Constructor Details

#initialize(enabled, str, filename = "") ⇒ BaseExecuter

Returns a new instance of BaseExecuter.



3
4
5
6
7
8
9
# File 'lib/couch_migrate/base_executer.rb', line 3

def initialize(enabled, str, filename = "")
  raise "'enabled' argument must be an Array of symbols (such as [:up, :down] or []" unless enabled.is_a?(Array)
  @migration_str = str
  @enabled = enabled
  @filename = filename
  self
end

Instance Method Details

#goObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/couch_migrate/base_executer.rb', line 11

def go
  Namespaced.module_eval(<<-EOS, __FILE__, __LINE__ + 1)
    def self.up
      yield if #{@enabled.include?(:up)}
    end

    def self.down
      yield if #{@enabled.include?(:down)}
    end

    # convenience method for migration files to use
    def self.use_couchrest_model
      require 'couch_migrate/couchrest_model/extend.rb'
    end

  EOS

  Namespaced.module_eval(@migration_str, @filename)
end