Class: Marbu::Models::MapReduceFinalize

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Fields::Serializable
Defined in:
lib/marbu/models/mrf/map_reduce_finalize.rb

Overview

represents one complete MapReduce-Model this model can be stored in a database and read again the builder will use MapReduce-Models to build actual mapreduce code

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ext_params = {}) ⇒ MapReduceFinalize

Returns a new instance of MapReduceFinalize.



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

def initialize(ext_params = {})
  # TODO: deep copy necessary why?
  params = default_params.merge( Marshal.load(Marshal.dump(ext_params)) )

  self.map                = params[:map]
  self.reduce             = params[:reduce]
  self.finalize           = params[:finalize]
  self.query              = params[:query]
  self.misc               = params[:misc]
end

Instance Attribute Details

#finalizeObject

Returns the value of attribute finalize.



12
13
14
# File 'lib/marbu/models/mrf/map_reduce_finalize.rb', line 12

def finalize
  @finalize
end

#mapObject

Returns the value of attribute map.



12
13
14
# File 'lib/marbu/models/mrf/map_reduce_finalize.rb', line 12

def map
  @map
end

#miscObject

Returns the value of attribute misc.



12
13
14
# File 'lib/marbu/models/mrf/map_reduce_finalize.rb', line 12

def misc
  @misc
end

#queryObject

Returns the value of attribute query.



12
13
14
# File 'lib/marbu/models/mrf/map_reduce_finalize.rb', line 12

def query
  @query
end

#reduceObject

Returns the value of attribute reduce.



12
13
14
# File 'lib/marbu/models/mrf/map_reduce_finalize.rb', line 12

def reduce
  @reduce
end

Instance Method Details

#==(other) ⇒ Object



78
79
80
# File 'lib/marbu/models/mrf/map_reduce_finalize.rb', line 78

def ==(other)
  eql?(other)
end

#default_paramsObject



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

def default_params
  {
    :map                => Map.new,
    :reduce             => Reduce.new,
    :finalize           => Finalize.new,
    :query              => Query.new,
    :misc               => Misc.new
  }
end

#deserialize(object) ⇒ Object



87
88
89
# File 'lib/marbu/models/mrf/map_reduce_finalize.rb', line 87

def deserialize(object)
  MapReduceFinalize.new(object.symbolize_keys_rec)
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/marbu/models/mrf/map_reduce_finalize.rb', line 74

def eql?(other)
  serializable_hash == other.serializable_hash
end

#mapreduce?Boolean

return true if we have a map and a reduce function defined

Returns:

  • (Boolean)


66
67
68
# File 'lib/marbu/models/mrf/map_reduce_finalize.rb', line 66

def mapreduce?
  !(map.nil? && reduce.nil?)
end

#query_only?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/marbu/models/mrf/map_reduce_finalize.rb', line 70

def query_only?
  force_query || (!mapreduce? && !query.nil?)
end

#serializable_hashObject



55
56
57
58
59
60
61
62
63
# File 'lib/marbu/models/mrf/map_reduce_finalize.rb', line 55

def serializable_hash
  {
    :map                        => map.serializable_hash,
    :reduce                     => reduce.serializable_hash,
    :finalize                   => finalize.serializable_hash,
    :query                      => query.serializable_hash,
    :misc                       => misc.serializable_hash
  }.delete_if{|k,v|v.blank?}
end

#serialize(object) ⇒ Object

TODO: please remove after Mongoid gets non-intrusive de/serialization



83
84
85
# File 'lib/marbu/models/mrf/map_reduce_finalize.rb', line 83

def serialize(object)
  object.serializable_hash
end