Class: Upkeep::Rails::Configuration::IdentityDefinition
- Inherits:
-
Object
- Object
- Upkeep::Rails::Configuration::IdentityDefinition
- Defined in:
- lib/upkeep/rails/configuration.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#source_key ⇒ Object
readonly
Returns the value of attribute source_key.
-
#subscribe_block ⇒ Object
readonly
Returns the value of attribute subscribe_block.
Instance Method Summary collapse
- #absent?(value) ⇒ Boolean
- #absent_dependency?(dependency) ⇒ Boolean
-
#initialize(name:, source:, source_key:, subscribe_block:, absent_block: nil) ⇒ IdentityDefinition
constructor
A new instance of IdentityDefinition.
- #matches_dependency?(dependency) ⇒ Boolean
- #matches_source?(source, key) ⇒ Boolean
- #source_label ⇒ Object
Constructor Details
#initialize(name:, source:, source_key:, subscribe_block:, absent_block: nil) ⇒ IdentityDefinition
Returns a new instance of IdentityDefinition.
16 17 18 19 20 21 22 |
# File 'lib/upkeep/rails/configuration.rb', line 16 def initialize(name:, source:, source_key:, subscribe_block:, absent_block: nil) @name = name.to_sym @source = source.to_sym @source_key = source_key @subscribe_block = subscribe_block @absent_block = absent_block end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
14 15 16 |
# File 'lib/upkeep/rails/configuration.rb', line 14 def name @name end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
14 15 16 |
# File 'lib/upkeep/rails/configuration.rb', line 14 def source @source end |
#source_key ⇒ Object (readonly)
Returns the value of attribute source_key.
14 15 16 |
# File 'lib/upkeep/rails/configuration.rb', line 14 def source_key @source_key end |
#subscribe_block ⇒ Object (readonly)
Returns the value of attribute subscribe_block.
14 15 16 |
# File 'lib/upkeep/rails/configuration.rb', line 14 def subscribe_block @subscribe_block end |
Instance Method Details
#absent?(value) ⇒ Boolean
56 57 58 59 60 |
# File 'lib/upkeep/rails/configuration.rb', line 56 def absent?(value) return value.nil? unless @absent_block @absent_block.arity == 1 ? @absent_block.call(value) : @absent_block.call end |
#absent_dependency?(dependency) ⇒ Boolean
62 63 64 |
# File 'lib/upkeep/rails/configuration.rb', line 62 def absent_dependency?(dependency) Upkeep::Dependencies.identity_absent_for?(dependency, name) end |
#matches_dependency?(dependency) ⇒ Boolean
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/upkeep/rails/configuration.rb', line 24 def matches_dependency?(dependency) case source when :current dependency.source == :current_attribute && (dependency, :owner) == source_key.fetch(:owner) && (dependency, :name) == source_key.fetch(:name) when :session dependency.source == :session && (dependency, :key) == source_key when :cookie dependency.source == :cookie && (dependency, :key) == source_key when :warden dependency.source == :warden_user && (dependency, :scope) == source_key else false end end |
#matches_source?(source, key) ⇒ Boolean
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/upkeep/rails/configuration.rb', line 41 def matches_source?(source, key) source = source.to_sym case self.source when :current source == :current && key.fetch(:owner).to_s == source_key.fetch(:owner) && key.fetch(:name).to_s == source_key.fetch(:name) when :session, :cookie, :warden source == self.source && key.to_s == source_key else false end end |
#source_label ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/upkeep/rails/configuration.rb', line 66 def source_label case source when :current "#{source_key.fetch(:owner)}.#{source_key.fetch(:name)}" when :session "session[:#{source_key}]" when :cookie "cookies[:#{source_key}]" when :warden "warden.user(:#{source_key})" end end |