Module: OpenIDConnect::RequestObject::Claimable
Class Method Summary collapse
Instance Method Summary collapse
- #accessible?(claim) ⇒ Boolean
- #as_json(options = {}) ⇒ Object
- #initialize(attributes = {}) ⇒ Object
- #optional?(claim) ⇒ Boolean (also: #voluntary?)
- #required?(claim) ⇒ Boolean (also: #essential?)
Class Method Details
.included(klass) ⇒ Object
4 5 6 |
# File 'lib/openid_connect/request_object/claimable.rb', line 4 def self.included(klass) klass.send :attr_optional, :claims end |
Instance Method Details
#accessible?(claim) ⇒ Boolean
49 50 51 |
# File 'lib/openid_connect/request_object/claimable.rb', line 49 def accessible?(claim) claims.try(:include?, claim) end |
#as_json(options = {}) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/openid_connect/request_object/claimable.rb', line 30 def as_json( = {}) keys = claims.try(:keys) hash = super Array(keys).each do |key| hash[:claims][key] ||= nil end hash end |
#initialize(attributes = {}) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/openid_connect/request_object/claimable.rb', line 8 def initialize(attributes = {}) super if claims.present? _claims_ = {} claims.each do |key, value| _claims_[key] = case value when :optional, :voluntary { essential: false } when :required, :essential { essential: true } else value end end self.claims = _claims_.with_indifferent_access end end |
#optional?(claim) ⇒ Boolean Also known as: voluntary?
44 45 46 |
# File 'lib/openid_connect/request_object/claimable.rb', line 44 def optional?(claim) accessible?(claim) && !required?(claim) end |
#required?(claim) ⇒ Boolean Also known as: essential?
39 40 41 |
# File 'lib/openid_connect/request_object/claimable.rb', line 39 def required?(claim) accessible?(claim) && claims[claim].is_a?(Hash) && claims[claim][:essential] end |