class RightOn::ByGroup

Public Class Methods

new() click to toggle source
# File lib/right_on/by_group.rb, line 7
def initialize
  @rights_by_name = Hash[Right.all.map{|r| [r.name, r]}]
end
rights() click to toggle source
# File lib/right_on/by_group.rb, line 3
def self.rights
  new.by_groups
end

Public Instance Methods

by_groups() click to toggle source
# File lib/right_on/by_group.rb, line 11
def by_groups
  yaml_rights.each_pair.with_object({}) { |(group, right_names), hash|
    hash[group] = right_names
      .flat_map { |right_name| right_name_to_rights(right_name) }
  }.sort.to_h
end

Private Instance Methods

action_rights(controller, actions) click to toggle source
# File lib/right_on/by_group.rb, line 40
def action_rights(controller, actions)
  actions.map { |action| rights_by_name!("#{controller}##{action}") }
end
controller_rights(controller) click to toggle source
# File lib/right_on/by_group.rb, line 34
def controller_rights(controller)
  r = @rights_by_name[controller]
  return [] unless r
  [r]
end
right_name_to_rights(right_name) click to toggle source
# File lib/right_on/by_group.rb, line 24
def right_name_to_rights(right_name)
  case right_name
  when String # controller
    [rights_by_name!(right_name)]
  when Hash # controller + actions
    controller, actions = right_name.first
    controller_rights(controller) + action_rights(controller, actions)
  end
end
rights_by_name!(name) click to toggle source
# File lib/right_on/by_group.rb, line 44
def rights_by_name!(name)
  @rights_by_name[name] or fail RightOn::RightNotFound, name.inspect
end
yaml_rights() click to toggle source
# File lib/right_on/by_group.rb, line 20
def yaml_rights
  YAML.load_file(RightOn.rights_yaml)
end