Sha256: 96926b4cbf74ade7ecf9173a69f5abb4cff231624f3d4e2de4707abdebffb7c2

Contents?: true

Size: 1.46 KB

Versions: 16

Compression:

Stored size: 1.46 KB

Contents

module Shamu
  module Features

    # Add feature togggle support to an object.
    module Support
      extend ActiveSupport::Concern

      included do

        # ============================================================================
        # @!group Dependencies
        #

        # @!attribute
        # @return [Features::FeaturesService] the service used to resolve
        #     enabled features.
        attr_dependency :features_service, Features::FeaturesService, lazy: true

        #
        # @!endgroup Dependencies

      end

      private

        # @!visibility public
        #
        # Only execute the block if the current {Features::Context} has the
        # named featue enabled.
        #
        # @param [String] feature name.
        # @param [Boolean] override force the feature to be either on or off.
        # @yield Yields if the feature is enabled.
        # @yieldreturn the result of the block or nil if the feature wasn't
        #     enabled.
        def when_feature( feature, override: nil, &block )
          yield if override.nil? ? feature_enabled?( feature ) : override
        end

        # @!visibility public
        #
        # Determines if the given feature has been toggled.
        #
        # @param [Symbol] feature name of the feature to check.
        # @return [Boolean] true if the feature has been toggled on.
        def feature_enabled?( feature )
          features_service.enabled?( feature )
        end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
shamu-0.0.21 lib/shamu/features/support.rb
shamu-0.0.20 lib/shamu/features/support.rb
shamu-0.0.19 lib/shamu/features/support.rb
shamu-0.0.18 lib/shamu/features/support.rb
shamu-0.0.17 lib/shamu/features/support.rb
shamu-0.0.15 lib/shamu/features/support.rb
shamu-0.0.14 lib/shamu/features/support.rb
shamu-0.0.13 lib/shamu/features/support.rb
shamu-0.0.11 lib/shamu/features/support.rb
shamu-0.0.9 lib/shamu/features/support.rb
shamu-0.0.8 lib/shamu/features/support.rb
shamu-0.0.7 lib/shamu/features/support.rb
shamu-0.0.5 lib/shamu/features/support.rb
shamu-0.0.4 lib/shamu/features/support.rb
shamu-0.0.3 lib/shamu/features/support.rb
shamu-0.0.2 lib/shamu/features/support.rb