module RailsRbs::Controllers::Helpers

Helpers that are used across RailsRbs default controllers

Public Instance Methods

owner_id_field() click to toggle source

Based on the RailsRbs configuration returns the id field of the owner. This is simply derived using the owned_by configuration (@see RailsRbs Config). @return [String] name of the owner id field used in rules and rule_sets (e.g. user_id)

# File lib/rails_rbs/controllers/helpers.rb, line 16
def owner_id_field
  "#{RailsRbs.owned_by.to_s.camelize}_id"
end
render_view_fallback(view_path) { |fallback| ... } click to toggle source

Helper method that will render the view_path provided only if render_views is enabled (@see RailsRbs Config). If this configuration setting is false then simply yield the provided fallback block. @param view_path [String] the path to the view to be rendered @param fallback A block to yield if render_views is disabled

# File lib/rails_rbs/controllers/helpers.rb, line 24
def render_view_fallback(view_path, &fallback)
  if RailsRbs.render_views
    render view_path.gsub(/\Arule_sets/, RailsRbs.rule_set_view_dir).gsub(/\Arules/, RailsRbs.rule_view_dir)
  else
    yield fallback
  end
end
rule_owner() click to toggle source

Attempts to call the owner_access method stored by the RailsRbs configuration, only if owner_access is not falsey. @see RailsRbs Config @return Rule/RuleSet owner if owner_access is not false

# File lib/rails_rbs/controllers/helpers.rb, line 10
def rule_owner
  self.send(RailsRbs.owner_access.to_sym) if RailsRbs.owner_access
end