Class: Marbu::Server

Inherits:
Sinatra::Base
  • Object
show all
Defined in:
lib/marbu/server.rb

Instance Method Summary collapse

Instance Method Details

#add(model, type, name, function) ⇒ Object



204
205
206
207
208
209
210
# File 'lib/marbu/server.rb', line 204

def add(model, type, name, function)
  case type
    when 'key'      then model.add_key(name, function)
    when 'value'    then model.add_value(name, function)
    else raise Exception.new("#{type} is unknown")
  end
end

#build_mrm_from_params(params) ⇒ Object



148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/marbu/server.rb', line 148

def build_mrm_from_params(params)
  name                      = 'name'
  function                  = 'function'
  puts params.inspect

  if (uuid = params['uuid'])
    mrm                       = Marbu::Models::Db::MongoDb.find_or_create_by(uuid: uuid)
  else
    mrm = Marbu::Models::Db::MongoDb.new
  end
  mrm.name                  = params['name']
  mrf                       = mrm.map_reduce_finalize

  mrf.map                   = Marbu::Models::Map.new(
                                :code => {:text => params['map_code']}
                              )
  mrf.reduce                = Marbu::Models::Reduce.new(
                                :code => {:text => params['reduce_code']}
                              )
  mrf.finalize              = Marbu::Models::Finalize.new(
                                :code => {:text => params['finalize_code']}
                              )
  mrf.query                 = Marbu::Models::Query.new(
                                condition:      params['query_condition'],
                                force_query:    params['query_force_query'],
                                static:         params['query_static']
                              )
  mrf.misc                  = Marbu::Models::Misc.new(
                                :database           => params['database'],
                                :input_collection   => params['input_collection'],
                                :output_collection  => params['output_collection']
                              )

  # add params to map_new, reduce_new, finalize_new
  ['map', 'reduce', 'finalize'].each do |stage|
    ['key', 'value'].each do |type|
      stage_type_name       = params["#{stage}_#{type}_#{name}"]
      stage_type_function   = params["#{stage}_#{type}_#{function}"]

      if( stage_type_name.present?)
        stage_type_name.each_with_index do |n, i|
          case stage
            when 'map'      then add(mrf.map, type, n, stage_type_function[i])
            when 'reduce'   then add(mrf.reduce, type, n, stage_type_function[i])
            when 'finalize' then add(mrf.finalize, type, n, stage_type_function[i])
            else raise Exception.new("#{stage} in #{k} is unknown")
          end
        end
      end
    end
  end

  mrm.map_reduce_finalize = mrf
  return mrm
end

#show(page) ⇒ Object



212
213
214
# File 'lib/marbu/server.rb', line 212

def show(page)
  haml page.to_sym
end