Class: Marbu::Models::Misc

Inherits:
Object
  • Object
show all
Defined in:
lib/marbu/models/mrf/misc.rb

Constant Summary collapse

VALUE =
:value
DOCUMENT_OFFSET =
VALUE.to_s + "."

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ext_params = {}) ⇒ Misc

Returns a new instance of Misc.



15
16
17
18
19
20
21
22
23
# File 'lib/marbu/models/mrf/misc.rb', line 15

def initialize( ext_params = {} )
  params              = default_params.merge( ext_params.delete_if{|k,v|v.blank?} )

  self.database           = params[:database]
  self.input_collection   = params[:input_collection]
  self.output_collection  = params[:output_collection]
  self.output_operation   = params[:output_operation]
  self.filter_data        = params[:filter_data]
end

Instance Attribute Details

#databaseObject

Returns the value of attribute database.



4
5
6
# File 'lib/marbu/models/mrf/misc.rb', line 4

def database
  @database
end

#document_offsetObject

Returns the value of attribute document_offset.



10
11
12
# File 'lib/marbu/models/mrf/misc.rb', line 10

def document_offset
  @document_offset
end

#filter_dataObject

if filter_data is true, a query will be created depending on the filter parameters in filter_model if filter_data is false, no query will generated this is necessary for multiple sequentiell map_reduces: some will work on already filtered data (so no filter needed) while others will grab data from other collections which need to be filtered first



9
10
11
# File 'lib/marbu/models/mrf/misc.rb', line 9

def filter_data
  @filter_data
end

#input_collectionObject

Returns the value of attribute input_collection.



4
5
6
# File 'lib/marbu/models/mrf/misc.rb', line 4

def input_collection
  @input_collection
end

#output_collectionObject

Returns the value of attribute output_collection.



4
5
6
# File 'lib/marbu/models/mrf/misc.rb', line 4

def output_collection
  @output_collection
end

#output_operationObject

Returns the value of attribute output_operation.



4
5
6
# File 'lib/marbu/models/mrf/misc.rb', line 4

def output_operation
  @output_operation
end

#valueObject

Returns the value of attribute value.



10
11
12
# File 'lib/marbu/models/mrf/misc.rb', line 10

def value
  @value
end

Instance Method Details

#blank?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/marbu/models/mrf/misc.rb', line 46

def blank?
  !present?
end

#collectionObject



60
61
62
# File 'lib/marbu/models/mrf/misc.rb', line 60

def collection
  Marbu.connection.db(database).collection(input_collection)
end

#default_paramsObject



25
26
27
28
29
30
31
32
# File 'lib/marbu/models/mrf/misc.rb', line 25

def default_params
  {
    :value              => VALUE,
    :document_offset    => DOCUMENT_OFFSET,
    :filter_data        => false,
    :output_operation   => "replace"
  }
end

#present?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/marbu/models/mrf/misc.rb', line 42

def present?
  database.present? || input_collection.present? || output_collection.present?
end

#serializable_hashObject



50
51
52
53
54
55
56
57
58
# File 'lib/marbu/models/mrf/misc.rb', line 50

def serializable_hash
  {
    :database           => database,
    :input_collection   => input_collection,
    :output_collection  => output_collection,
    :output_operation   => output_operation,
    :filter_data        => filter_data
  }.delete_if{|k,v|v.blank?}
end