Module: Releaf::ActionController::Features

Extended by:
ActiveSupport::Concern
Included in:
Releaf::ActionController
Defined in:
app/lib/releaf/action_controller/features.rb

Instance Method Summary collapse

Instance Method Details

#action_feature(action) ⇒ Object


15
16
17
# File 'app/lib/releaf/action_controller/features.rb', line 15

def action_feature(action)
  action_features[action.to_sym]
end

#action_featuresObject


23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/lib/releaf/action_controller/features.rb', line 23

def action_features
  {
    index: :index,
    new: :create,
    create: :create,
    show: (feature_available?(:show) ? :show : :edit),
    edit: :edit,
    update: :edit,
    confirm_destroy: :destroy,
    destroy: :destroy
  }
end

#feature_available?(feature) ⇒ Boolean

Returns:

  • (Boolean)

36
37
38
39
40
41
# File 'app/lib/releaf/action_controller/features.rb', line 36

def feature_available?(feature)
  return false if feature.blank?
  return false if feature == :create_another && !feature_available?(:create)
  return false if feature == :search && !feature_available?(:index)
  features.include? feature
end

#featuresObject


19
20
21
# File 'app/lib/releaf/action_controller/features.rb', line 19

def features
  [:edit, :create, :create_another, :destroy, :index, :toolbox, :search]
end

#verify_feature_availability!Object


10
11
12
13
# File 'app/lib/releaf/action_controller/features.rb', line 10

def verify_feature_availability!
  feature = action_feature(params[:action])
  raise Releaf::FeatureDisabled, feature.to_s if feature.present? && !feature_available?(feature)
end