Module: Arturo::FeatureAvailability

Defined in:
lib/arturo/feature_availability.rb

Overview

A mixin that provides #feature_enabled? and #if_feature_enabled methods; to be mixed in by Controllers and Helpers. The including class must return some “thing that has features” (e.g. a User, Person, or Account) when Arturo.feature_recipient is bound to an instance and called.

See Also:

  • feature_recipient

Instance Method Summary collapse

Instance Method Details

#feature_enabled?(symbol_or_feature) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
16
17
# File 'lib/arturo/feature_availability.rb', line 13

def feature_enabled?(symbol_or_feature)
  feature = ::Arturo::Feature.to_feature(symbol_or_feature)
  return false if feature.blank?
  feature.enabled_for?(feature_recipient)
end

#feature_recipientObject

By default, returns current_user.

If you would like to change this implementation, it is recommended you do so in config/initializers/arturo_initializer.rb

Returns:

  • (Object)

    the recipient of features.



32
33
34
# File 'lib/arturo/feature_availability.rb', line 32

def feature_recipient
  current_user
end

#if_feature_enabled(symbol_or_feature, &block) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/arturo/feature_availability.rb', line 19

def if_feature_enabled(symbol_or_feature, &block)
  if feature_enabled?(symbol_or_feature)
    block.call
  else
    nil
  end
end