Module: Fortress::Mechanism

Defined in:
lib/fortress/mechanism.rb

Overview

Mechanism embbed all the logic of the Fortress library.

Author:

  • zedtux

Class Method Summary collapse

Class Method Details

.append_or_update(controller_name, key, value) ⇒ Object



68
69
70
71
72
73
74
75
76
# File 'lib/fortress/mechanism.rb', line 68

def self.append_or_update(controller_name, key, value)
  authorisations[controller_name] ||= {}

  if authorisations[controller_name].key?(key)
    update_authorisations(controller_name, key, value)
  else
    append_to_authorisations(controller_name, key, value)
  end
end

.authorise!(class_name, actions) ⇒ Object



78
79
80
81
82
83
84
# File 'lib/fortress/mechanism.rb', line 78

def self.authorise!(class_name, actions)
  if actions == :all
    append_or_update(class_name, :all, true)
    return
  end
  append_or_update(class_name, :only, Array(actions))
end

.initialize_authorisationsObject



53
54
55
# File 'lib/fortress/mechanism.rb', line 53

def self.initialize_authorisations
  self.authorisations = {}
end

.parse_options(controller, actions, options) ⇒ Object



57
58
59
60
61
62
63
64
65
66
# File 'lib/fortress/mechanism.rb', line 57

def self.parse_options(controller, actions, options)
  options.each do |key, value|
    case key
    when :if
      Mechanism.authorise_if_truthy(controller.name, value, actions)
    when :except
      Mechanism.authorise_excepted(controller.name, value)
    end
  end
end