Module: Caster

Defined in:
lib/caster.rb,
lib/caster/accessor.rb,
lib/caster/migrator.rb,
lib/caster/execution.rb,
lib/caster/migration.rb,
lib/caster/operation.rb,
lib/caster/reference.rb,
lib/caster/transform/add.rb,
lib/caster/transform/clone.rb,
lib/caster/transform/create.rb,
lib/caster/transform/delete.rb,
lib/caster/transform/remove.rb,
lib/caster/transform/rename.rb,
lib/caster/metadata/metadata_store.rb,
lib/caster/metadata/metadata_database.rb,
lib/caster/metadata/metadata_document.rb

Defined Under Namespace

Modules: MetadataStore Classes: Accessor, Add, Clone, Create, Delete, Execution, MetadataDatabase, MetadataDocument, Migrator, Operation, Reference, Remove, Rename

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object

fall down to couchrest methods



32
33
34
35
36
37
38
# File 'lib/caster/migration.rb', line 32

def method_missing method_name, *args
  if @db.respond_to? method_name
    @db.send method_name, *args
  else
    super
  end
end

Class Method Details

.configObject



28
29
30
# File 'lib/caster.rb', line 28

def self.config
  @config
end

.configure(opts = {}) ⇒ Object



36
37
38
39
40
# File 'lib/caster.rb', line 36

def self.configure opts = {}
  opts.each do |k, v|
    @config[k] = v if @valid_config_keys.include? k
  end
end

.configure_with(path_to_yaml_file) ⇒ Object



42
43
44
45
46
47
48
49
50
51
# File 'lib/caster.rb', line 42

def self.configure_with path_to_yaml_file
  begin
    configure(YAML.load_file path_to_yaml_file)
  rescue Errno::ENOENT
    Caster.log.warn { "YAML configuration file couldn't be found.. using defaults" }
  rescue Psych::SyntaxError
    Caster.log.warn { "YAML configuration file contains invalid syntax.. using defaults" }
  end
  Caster.log.info { "using configuration: #{@config.inspect}" }
end

.logObject



32
33
34
# File 'lib/caster.rb', line 32

def self.log
  @logger
end

Instance Method Details

#migrate(database_name, &block) ⇒ Object



5
6
7
8
9
# File 'lib/caster/migration.rb', line 5

def migrate database_name, &block
  @db = CouchRest.database "http://#{Caster.config['host']}:#{Caster.config['port']}/#{database_name}"
  yield
  @db = nil
end

#migrate_script(database_name, code) ⇒ Object



11
12
13
14
15
# File 'lib/caster/migration.rb', line 11

def migrate_script database_name, code
  migrate database_name do
    self.instance_eval code, __FILE__, __LINE__
  end
end

#over(scope, query = {}, &block) ⇒ Object



17
18
19
20
21
# File 'lib/caster/migration.rb', line 17

def over scope, query = {}, &block
  database_name, view = split_view_accessor(scope)
  db = CouchRest.database "http://#{Caster.config['host']}:#{Caster.config['port']}/#{database_name}" if @db == nil
  Execution.new(db || @db, view, query, &block).execute
end

#split_view_accessor(scope) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/caster/migration.rb', line 23

def split_view_accessor scope
  if scope.count('/') == 1
    return nil, scope
  elsif scope.count('/') == 2
    return scope.split('/', 2)
  end
end