Class: DeployCouch::DeltaProcessor
- Inherits:
-
Object
- Object
- DeployCouch::DeltaProcessor
- Defined in:
- lib/deploy_couch/delta_processor.rb
Instance Method Summary collapse
- #apply ⇒ Object
-
#initialize(next_type_version, config, delta, repository) ⇒ DeltaProcessor
constructor
A new instance of DeltaProcessor.
- #rollback ⇒ Object
Constructor Details
#initialize(next_type_version, config, delta, repository) ⇒ DeltaProcessor
Returns a new instance of DeltaProcessor.
4 5 6 7 8 9 |
# File 'lib/deploy_couch/delta_processor.rb', line 4 def initialize(next_type_version,config,delta,repository) @repository = repository @delta = delta @config = config @next_type_version = next_type_version end |
Instance Method Details
#apply ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/deploy_couch/delta_processor.rb', line 11 def apply user_map_function = @delta.map_function.gsub("\"","\\\"") map_function = <<-JSON { "map":"function(doc){if(doc.#{@config.doc_type_field}=='#{@delta.type}' && (!doc.#{@config.type_version_field} || doc.#{@config.type_version_field} < #{@next_type_version})){new_doc = eval(uneval(doc)); var method = map(new_doc); if(method) emit(method,new_doc);}} #{user_map_function}" } JSON modify_document(map_function,@next_type_version) end |
#rollback ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/deploy_couch/delta_processor.rb', line 22 def rollback user_rollback_function = @delta.rollback_function.gsub("\"","\\\"") current_type_version = @next_type_version - 1 rollback_function = <<-JSON { "map":"function(doc){if(doc.#{@config.doc_type_field}=='#{@delta.type}' && (doc.#{@config.type_version_field} >= #{current_type_version})){new_doc = eval(uneval(doc)); var method = map(new_doc); if(method) emit(method,new_doc);}} #{user_rollback_function}" } JSON modify_document(rollback_function,current_type_version-1) end |