Class: JsonApiServer::Configuration
- Inherits:
-
Object
- Object
- JsonApiServer::Configuration
- Defined in:
- lib/json_api_server/configuration.rb
Overview
Description
Configurations for the gem.
-
Be sure to configure :base_url which defaults to nil.
-
Logger defaults to Logger.new(STDOUT). If using Rails, configure to Rails.logger.
-
Custom builders can be added to :filter_builders.
-
Default builders can be substituted.
Example
# config/initializers/json_api_server.rb
# example of custom filter builder
module JsonApiServer
class MyCustomFilter < FilterBuilder
def to_query(model)
model.where("#{column_name} LIKE :val", val: "%#{value}%")
end
end
end
JsonApiServer.configure do |c|
c.base_url = 'http://localhost:3001' # or ENV['HOSTNAME']
c.filter_builders = c.filter_builders
.merge({my_custom_builder: JsonApiServer::MyCustomFilter})
c.logger = Rails.logger
end
Constant Summary collapse
- DEFAULT_SERIALIZER_OPTIONS =
Serializer options for the OJ gem.
{ escape_mode: :xss_safe, time: :xmlschema, mode: :compat }.freeze
- DEFAULT_FILTER_BUILDERS =
Default filter builders. For generating queries based on on requested filters.
{ sql_eql: JsonApiServer::SqlEql, sql_comparison: JsonApiServer::SqlComp, sql_in: JsonApiServer::SqlIn, sql_like: JsonApiServer::SqlLike, pg_ilike: JsonApiServer::PgIlike, pg_jsonb_array: JsonApiServer::PgJsonbArray, pg_jsonb_ilike_array: JsonApiServer::PgJsonbIlikeArray, model_query: JsonApiServer::ModelQuery }.freeze
Instance Attribute Summary collapse
-
#base_url ⇒ Object
Root url i.e., www.example.com.
-
#default_builder ⇒ Object
Defaults to sql_eql: JsonApiServer::SqlEql.
-
#default_comparison_builder ⇒ Object
Defaults to sql_comparison: JsonApiServer::SqlComp.
-
#default_in_builder ⇒ Object
Defaults to sql_in: JsonApiServer::SqlIn.
-
#default_like_builder ⇒ Object
Defaults to sql_like: JsonApiServer::SqlLike.
-
#default_max_per_page ⇒ Object
Pagination option.
-
#default_per_page ⇒ Object
Pagination option.
-
#filter_builders ⇒ Object
Defaults to DEFAULT_FILTER_BUILDERS.
-
#logger ⇒ Object
Defaults to Logger.new(STDOUT).
-
#serializer_options ⇒ Object
JSON is serialized with OJ gem.
Instance Method Summary collapse
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/json_api_server/configuration.rb', line 86 def initialize @base_url = nil @default_max_per_page = 100 @default_per_page = 20 @default_like_builder = :sql_like @default_in_builder = :sql_in @default_comparison_builder = :sql_comparison @default_builder = :sql_eql @serializer_options = DEFAULT_SERIALIZER_OPTIONS @filter_builders = DEFAULT_FILTER_BUILDERS @logger = Logger.new(STDOUT) end |
Instance Attribute Details
#base_url ⇒ Object
Root url i.e., www.example.com. Used in pagination links.
33 34 35 |
# File 'lib/json_api_server/configuration.rb', line 33 def base_url @base_url end |
#default_builder ⇒ Object
Defaults to sql_eql: JsonApiServer::SqlEql.
58 59 60 |
# File 'lib/json_api_server/configuration.rb', line 58 def default_builder @default_builder end |
#default_comparison_builder ⇒ Object
Defaults to sql_comparison: JsonApiServer::SqlComp. For <,>, <=, >=, etc. queries.
55 56 57 |
# File 'lib/json_api_server/configuration.rb', line 55 def default_comparison_builder @default_comparison_builder end |
#default_in_builder ⇒ Object
Defaults to sql_in: JsonApiServer::SqlIn. For IN (x,y,z) queries.
51 52 53 |
# File 'lib/json_api_server/configuration.rb', line 51 def default_in_builder @default_in_builder end |
#default_like_builder ⇒ Object
Defaults to sql_like: JsonApiServer::SqlLike. If using Postgres, it can be replaced with pg_ilike: JsonApiServer::PgIlike.
48 49 50 |
# File 'lib/json_api_server/configuration.rb', line 48 def default_like_builder @default_like_builder end |
#default_max_per_page ⇒ Object
Pagination option. Default maximum number of records to show per page. Defaults to 100.
37 38 39 |
# File 'lib/json_api_server/configuration.rb', line 37 def default_max_per_page @default_max_per_page end |
#default_per_page ⇒ Object
Pagination option. Default number of records to show per page. Defaults to 20.
41 42 43 |
# File 'lib/json_api_server/configuration.rb', line 41 def default_per_page @default_per_page end |
#filter_builders ⇒ Object
Defaults to DEFAULT_FILTER_BUILDERS.
61 62 63 |
# File 'lib/json_api_server/configuration.rb', line 61 def filter_builders @filter_builders end |
#logger ⇒ Object
Defaults to Logger.new(STDOUT)
64 65 66 |
# File 'lib/json_api_server/configuration.rb', line 64 def logger @logger end |
#serializer_options ⇒ Object
JSON is serialized with OJ gem. Options are defined in DEFAULT_SERIALIZER_OPTIONS.
44 45 46 |
# File 'lib/json_api_server/configuration.rb', line 44 def @serializer_options end |