Module: Flipper::Api

Defined in:
lib/flipper/api.rb,
lib/flipper/api/error.rb,
lib/flipper/api/action.rb,
lib/flipper/api/middleware.rb,
lib/flipper/api/json_params.rb,
lib/flipper/api/error_response.rb,
lib/flipper/api/action_collection.rb,
lib/flipper/api/v1/actions/actors.rb,
lib/flipper/api/v1/actions/feature.rb,
lib/flipper/api/v1/decorators/gate.rb,
lib/flipper/api/v1/actions/features.rb,
lib/flipper/api/v1/decorators/actor.rb,
lib/flipper/api/v1/decorators/feature.rb,
lib/flipper/api/v1/actions/actors_gate.rb,
lib/flipper/api/v1/actions/groups_gate.rb,
lib/flipper/api/v1/actions/boolean_gate.rb,
lib/flipper/api/v1/actions/clear_feature.rb,
lib/flipper/api/v1/actions/percentage_of_time_gate.rb,
lib/flipper/api/v1/actions/percentage_of_actors_gate.rb

Defined Under Namespace

Modules: ErrorResponse, V1 Classes: Action, ActionCollection, JsonParams, Middleware

Constant Summary collapse

CONTENT_TYPE =
'application/json'.freeze
Error =

All flipper api errors inherit from this.

Class.new(StandardError)
RequestMethodNotSupported =

Raised when a request method (get, post, etc.) is called for an action that does not know how to handle it.

Class.new(Error)

Class Method Summary collapse

Class Method Details

.app(flipper = nil, options = {}) {|builder| ... } ⇒ Object

Yields:

  • (builder)


10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/flipper/api.rb', line 10

def self.app(flipper = nil, options = {})
  env_key = options.fetch(:env_key, 'flipper')
  app = ->(_) { [404, { 'Content-Type'.freeze => CONTENT_TYPE }, ['{}'.freeze]] }
  builder = Rack::Builder.new
  yield builder if block_given?
  builder.use Flipper::Api::JsonParams
  builder.use Flipper::Middleware::SetupEnv, flipper, env_key: env_key
  builder.use Flipper::Api::Middleware, env_key: env_key
  builder.run app
  klass = self
  app = builder.to_app
  app.define_singleton_method(:inspect) { klass.inspect } # pretty rake routes output
  app
end