Module: Zendesk::Strategy::Ruby

Extended by:
Ruby
Included in:
Ruby
Defined in:
lib/zendesk/strategy/ruby.rb

Instance Method Summary collapse

Instance Method Details

#execute(db, command_ast, results = Hash.new { |hash, key| hash[key] = [] }) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/zendesk/strategy/ruby.rb', line 23

def execute(db, command_ast, results = Hash.new { |hash, key| hash[key] = [] })
  db.keys.each do |table_name|
    db[table_name].each do |row|
      command_ast.each do |op, context|
        matched = match_op(op, context, row)

        results[table_name] << row if matched
      end
    end
  end

  results
end

#load_files(file_paths) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/zendesk/strategy/ruby.rb', line 10

def load_files(file_paths)
  db = Hash.new { |hash, key| hash[key] = [] }

  file_paths.inject(db) do |db, file_path|
    table_name = File.basename file_path, '.json'
    table_data = JSON.load File.read file_path

    table_data.each_with_object(db) do |row, db|
      db[table_name] << row
    end
  end
end