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)


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

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.



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

def feature_recipient
  current_user
end

#if_feature_enabled(symbol_or_feature, &block) ⇒ Object



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

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