Sha256: f12c14c9a17250a4b20555826d7210cac4ddb1e422dc0deef7892bf224866475

Contents?: true

Size: 813 Bytes

Versions: 4

Compression:

Stored size: 813 Bytes

Contents

require 'delegate'

module Flipper
  module Api
    module V1
      module Decorators
        class Actor < SimpleDelegator
          # Public: the actor and features.
          attr_reader :actor, :features

          def initialize(actor, features)
            @actor = actor
            @features = features
          end

          def as_json
            {
              'flipper_id' => actor.flipper_id,
              'features' => features_data,
            }
          end

          private

          def features_data
            features.each_with_object({}) do |feature, features_hash|
              features_hash[feature.name] = {
                'enabled' => feature.enabled?(actor),
              }
              features_hash
            end
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
flipper-api-1.3.2 lib/flipper/api/v1/decorators/actor.rb
flipper-api-1.3.1 lib/flipper/api/v1/decorators/actor.rb
flipper-api-1.3.0 lib/flipper/api/v1/decorators/actor.rb
flipper-api-1.3.0.pre lib/flipper/api/v1/decorators/actor.rb