Rubyフレームワーク - サポート終了
重要
Rubyエージェントは現在、新規のお客様への販売は行っておりません。Ruby言語の製品およびサポートについてご質問がある場合は、弊社の営業担当までお問い合わせ下さい。
アプリケーションフレームワークとはソフトウェアのライブラリで、アプリケーション開発を支援するための基礎的な構造を提供します。
お使いのフレームワークに合わせて、以下の各ガイドラインに従ってください。
Railsでの設定
Railsを使用している場合、RubyエージェントはRailtieとして機能するため追加の設定は必要ありません。
Sinatraでの設定
Sinatraフレームワークを使用している場合、Rubyエージェントを使用するためにアプリケーションを設定する必要があります。Rubyエージェントを使用するように設定した簡単なアプリケーションは、以下の例のようになります。
require 'sinatra' require 'contrast-agent' class App < Sinatra::Base use Contrast::Agent::Middleware, true end
config.ruでSinatraを設定
クラスが拡張されていない場合、Sinatra::Baseまたはconfig.ruが、以下の設定でRackアプリケーションを起動するデフォルトの方法です。
config.ru
# frozen_string_literal: true # Require Sinatra early for Framework support to detect it. require 'sinatra' # example app.rb, could be any file implementing Sinatra # endpoints and logic. # # For instance: # # # frozen_string_literal: true # # require 'sinatra' # # get '/frank-says' do # 'Put this in your pipe & smoke it!' # end # require './app.rb' # Contrast Agent needs to be required after sinatra. require 'contrast-agent' # Example for requiring gems: require 'bundler/setup' Bundler.require(:default) # Add Contrast Agent middleware to the rack stack: use Contrast::Agent::Middleware, true # Run Sinatra application: run Sinatra::Application
アプリケーションを起動します。
bundle exec rackup
または
bundle exec rackup config.ru
Grapeでの設定
Grapeフレームワークを使用している場合、Rubyエージェントを使用するためにアプリケーションを設定する必要があります。Rubyエージェントを使用するように設定した簡単なアプリケーションは、以下の例のようになります。
require 'grape' require 'contrast-agent' class App < Grape::API use Contrast::Agent::Middleware, true end
config.ruでGrapeを設定
クラスが拡張されていない場合、Grape::API またはconfig.ruが、以下の設定でRackアプリケーションを起動するデフォルトの方法です。
config.ru
# frozen_string_literal: true
require 'rack'
# Require Grape early for Framework support to detect it.
require 'Grape'
# example app.rb, could be any file implementing Grape
# endpoints and logic.
#
# For instance:
#
# # frozen_string_literal: true
#
# require 'Grape'
#
# class App
# def initialize
# @filenames = ['', '.html', 'index.html', '/index.html']
# @rack_static = ::Rack::Static.new(
# lambda { [404, {}, []] },
# root: File.expand_path('../public', __dir__),
# urls: ['/']
# )
# end
#
# def self.instance
# @instance ||= Rack::Builder.new do
# use Rack::Cors do
# allow do
# origins '*'
# resource '*', headers: :any, methods: :get
# end
# end
#
# run App.new
# end.to_app
# end
# def call(env)
# # Grape::API impleted in API module:
# API.call(env)
# # handle response
# ......
# end
# end
#
require './app.rb'
# Contrast Agent needs to be required after Grape.
require 'contrast-agent'
# Example for requiring gems:
require 'bundler/setup'
Bundler.require(:default)
# Add Contrast Agent middleware to the rack stack:
use Contrast::Agent::Middleware, true
# Run Grape application:
run App.instanceアプリケーションを起動します。
bundle exec rackup
または
bundle exec rackup config.ru