Module: Consent::SubjectCoder

Defined in:
lib/consent/subject_coder.rb

Overview

Coder for ability subjects

Class Method Summary collapse

Class Method Details

.dump(key) ⇒ String

Dumps a serialized key (snake case string) from a valid permission subject (a constant or a symbol)

Parameters:

  • key (Module, Class, Symbol)

    the subject key

Returns:

  • (String)


25
26
27
# File 'lib/consent/subject_coder.rb', line 25

def dump(key)
  key.to_s.underscore
end

.load(key) ⇒ Module, ...

Loads the serialized key (snake case string) as a valid permission subject (a constant or a symbol)

Parameters:

  • key (String)

    snake case string representing a subject

Returns:

  • (Module, Class, Symbol)


13
14
15
16
17
18
# File 'lib/consent/subject_coder.rb', line 13

def load(key)
  return nil unless key

  constant = key.camelize.safe_constantize
  constant.is_a?(Class) ? constant : key.to_sym
end