Module: Arturo

Defined in:
app/models/arturo/feature.rb,
lib/arturo.rb,
lib/arturo/engine.rb,
lib/arturo/middleware.rb,
lib/arturo/feature_caching.rb,
lib/arturo/special_handling.rb,
lib/arturo/controller_filters.rb,
lib/arturo/feature_management.rb,
lib/arturo/feature_availability.rb,
app/helpers/arturo/features_helper.rb,
lib/generators/arturo/assets_generator.rb,
lib/generators/arturo/routes_generator.rb,
lib/generators/arturo/migration_generator.rb,
app/controllers/arturo/features_controller.rb,
lib/generators/arturo/initializer_generator.rb

Overview

TODO: this doesn’t do anything radically out of the ordinary.

Are there Rails 3 patterns/mixins/methods I can use
to clean it up a bit?

Defined Under Namespace

Modules: ControllerFilters, FeatureAvailability, FeatureCaching, FeatureManagement, FeaturesHelper, SpecialHandling Classes: AssetsGenerator, Engine, Feature, FeaturesController, InitializerGenerator, Middleware, MigrationGenerator, RoutesGenerator

Constant Summary collapse

ENABLED_FOR_METHOD_NAME =
/^(\w+)_enabled_for\?$/

Class Method Summary collapse

Class Method Details

.feature_enabled_for?(feature_name, recipient) ⇒ true, false

Quick check for whether a feature is enabled for a recipient.

Parameters:

  • feature_name (String, Symbol)
  • recipient (#id)

Returns:

  • (true, false)

    whether the feature exists and is enabled for the recipient



17
18
19
20
# File 'lib/arturo.rb', line 17

def feature_enabled_for?(feature_name, recipient)
  f = self::Feature.to_feature(feature_name)
  f && f.enabled_for?(recipient)
end

.method_missing(symbol, *args, &block) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/arturo.rb', line 28

def method_missing(symbol, *args, &block)
  if (args.length == 1 && match = ENABLED_FOR_METHOD_NAME.match(symbol.to_s))
    feature_enabled_for?(match[1], args[0])
  else
    super(symbol, *args, &block)
  end
end

.respond_to?(symbol) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/arturo.rb', line 24

def respond_to?(symbol)
  symbol.to_s =~ ENABLED_FOR_METHOD_NAME || super(symbol)
end