Sha256: 81f7605928c422d03ff810276ca2d353add546754608c1e1ff9c69aa4ec305f9

Contents?: true

Size: 1.35 KB

Versions: 35

Compression:

Stored size: 1.35 KB

Contents

namespace :graphiti do
  def session
    @session ||= ActionDispatch::Integration::Session.new(Rails.application)
  end

  def setup_rails!
    Rails.application.eager_load!
    Rails.application.config.cache_classes = true
    Rails.application.config.action_controller.perform_caching = false
  end

  def make_request(path, debug = false)
    if path.split('/').length == 2
      path = "#{ApplicationResource.endpoint_namespace}#{path}"
    end
    if path.include?('?')
      path << '&cache=bust'
    else
      path << '?cache=bust'
    end
    path = "#{path}&debug=true" if debug
    session.get("#{path}")
    JSON.parse(session.response.body)
  end

  desc "Execute request without web server."
  task :request, [:path,:debug] => [:environment] do |_, args|
    setup_rails!
    Graphiti.logger = Graphiti.stdout_logger
    Graphiti::Debugger.preserve = true
    require 'pp'
    path, debug = args[:path], args[:debug]
    puts "Graphiti Request: #{path}"
    json = make_request(path, debug)
    pp json
    Graphiti::Debugger.flush if debug
  end

  desc "Execute benchmark without web server."
  task :benchmark, [:path,:requests] => [:environment] do |_, args|
    setup_rails!
    took = Benchmark.ms do
      args[:requests].to_i.times do
        make_request(args[:path])
      end
    end
    puts "Took: #{(took / args[:requests].to_f).round(2)}ms"
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
graphiti-1.0.rc.21 lib/graphiti/tasks.rb
graphiti-1.0.rc.19 lib/graphiti/tasks.rb
graphiti-1.0.rc.18 lib/graphiti/tasks.rb
graphiti-1.0.rc.17 lib/graphiti/tasks.rb
graphiti-1.0.rc.16 lib/graphiti/tasks.rb
graphiti-1.0.rc.15 lib/graphiti/tasks.rb
graphiti-1.0.rc.14 lib/graphiti/tasks.rb
graphiti-1.0.rc.12 lib/graphiti/tasks.rb
graphiti-1.0.rc.11 lib/graphiti/tasks.rb
graphiti-1.0.rc.10 lib/graphiti/tasks.rb
graphiti-1.0.rc.9 lib/graphiti/tasks.rb
graphiti-1.0.rc.8 lib/graphiti/tasks.rb
graphiti-1.0.rc.7 lib/graphiti/tasks.rb
graphiti-1.0.rc.6 lib/graphiti/tasks.rb
graphiti-1.0.rc.5 lib/graphiti/tasks.rb
graphiti-1.0.rc.4 lib/graphiti/tasks.rb
graphiti-1.0.rc.3 lib/graphiti/tasks.rb
graphiti-1.0.rc.2 lib/graphiti/tasks.rb
graphiti-1.0.rc.1 lib/graphiti/tasks.rb
graphiti-1.0.beta.23 lib/graphiti/tasks.rb