Class: ActiveCouch::Migration

Inherits:
Object
  • Object
show all
Defined in:
lib/active_couch/migrations/migration.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.databaseObject

These are accessible only at class-scope



9
10
11
# File 'lib/active_couch/migrations/migration.rb', line 9

def database
  @database
end

.viewObject

These are accessible only at class-scope



9
10
11
# File 'lib/active_couch/migrations/migration.rb', line 9

def view
  @view
end

Class Method Details

.define(*args) ⇒ Object

Set the view name and database name in the define method and then execute the block



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/active_couch/migrations/migration.rb', line 12

def define(*args)
  # Borrowed from ActiveRecord::Base.find
  first = args.slice!(0); second = args.slice!(0)
  # Based on the classes of the arguments passed, set instance variables
  case first.class.to_s
    when 'String', 'Symbol' then view = first.to_s;  options = second || {}
    when 'Hash' then  view = ''; options = first
    else raise ArgumentError, "Wrong arguments used to define the view"
  end
  # Define the view and database instance variables based on the args passed
  # Don't care if the key doesn't exist
  @view, @database = get_view(view), options[:for_db]
  # Block being called to set other parameters for the Migration
  yield if block_given?
end

.include_attributes(*attrs) ⇒ Object



36
37
38
# File 'lib/active_couch/migrations/migration.rb', line 36

def include_attributes(*attrs)
  @attrs = attrs unless attrs.nil? || !attrs.is_a?(Array)
end

.view_jsObject



40
41
42
43
44
45
# File 'lib/active_couch/migrations/migration.rb', line 40

def view_js
  results_hash = {"_id" => "_design/#{@view}", "language" => "text/javascript"}
  results_hash["views"] =  { @view => view_function }
  # Returns the JSON format for the function
  results_hash.to_json
end

.with_filter(filter = "") ⇒ Object



32
33
34
# File 'lib/active_couch/migrations/migration.rb', line 32

def with_filter(filter = "")
  @filter = filter unless filter.nil?
end

.with_key(key = "") ⇒ Object



28
29
30
# File 'lib/active_couch/migrations/migration.rb', line 28

def with_key(key = "")
  @key = key unless key.nil?
end