lib/job.rb in trafficbroker-mandy-0.2.11 vs lib/job.rb in trafficbroker-mandy-0.2.12
- old
+ new
@@ -14,16 +14,21 @@
attr_reader :name
def initialize(name, &blk)
@name = name
@settings = {}
+ @modules = []
@mapper_class = Mandy::Mappers::PassThroughMapper
@reducer_class = Mandy::Reducers::PassThroughReducer
set('mapred.job.name', name)
instance_eval(&blk) if blk
end
+ def mixin(*modules)
+ modules.each {|m| @modules << m}
+ end
+
def set(key, value)
@settings[key.to_s] = value.to_s
end
def map_tasks(count)
@@ -43,13 +48,17 @@
end
end
def map(klass=nil, &blk)
@mapper_class = klass || Mandy::Mappers::Base.compile(&blk)
+ @modules.each {|m| @mapper_class.send(:include, m) }
+ @mapper_class
end
def reduce(klass=nil, &blk)
@reducer_class = klass || Mandy::Reducers::Base.compile(&blk)
+ @modules.each {|m| @reducer_class.send(:include, m) }
+ @reducer_class
end
def run_map(input=STDIN, output=STDOUT, &blk)
mapper = @mapper_class.new(input, output)
yield(mapper) if blk
\ No newline at end of file