Class: MrMongo::Loader

Inherits:
Object
  • Object
show all
Defined in:
lib/mr_mongo/loader.rb

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ Loader

Returns a new instance of Loader.



5
6
7
# File 'lib/mr_mongo/loader.rb', line 5

def initialize(context)
  @context = context
end

Instance Method Details

#load(file) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/mr_mongo/loader.rb', line 9

def load(file)
  dsl_script = ::File.read(file).sub!(/^__END__\n.*\Z/m, '')

  map_reduce = load_from_string(dsl_script, file)

  InlineTemplateLoader.load(file).each do |key, val|
    map_reduce.send("#{key}=".to_sym, val)
  end

  map_reduce
end

#load_from_string(dsl_script, file = "(Mr. Mongo DSL)") ⇒ Object



21
22
23
24
25
# File 'lib/mr_mongo/loader.rb', line 21

def load_from_string(dsl_script, file = "(Mr. Mongo DSL)")
  dsl = Dsl.new(@context)

  eval "dsl.parse {\n" + dsl_script + "\n}.map_reduce", binding, file, 0
end