class Yoti::DynamicSharingService::DynamicPolicyBuilder

Builder for DynamicPolicy

Public Class Methods

new() click to toggle source
# File lib/yoti/dynamic_share_service/policy/dynamic_policy.rb, line 40
def initialize
  @policy = DynamicPolicy.new
  @wanted_auth_types = {}
  @wanted_attributes = {}
end

Public Instance Methods

build() click to toggle source
# File lib/yoti/dynamic_share_service/policy/dynamic_policy.rb, line 46
def build
  @policy.instance_variable_set(
    :@wanted_auth_types,
    @wanted_auth_types
      .select { |_, wanted| wanted }
      .keys
  )
  @policy.instance_variable_set(:@wanted, @wanted_attributes.values)
  Marshal.load Marshal.dump @policy
end
with_age_derived_attribute(derivation, constraints: nil) click to toggle source

@param [String] derivation @param [Array<SourceConstraint>] constraints

# File lib/yoti/dynamic_share_service/policy/dynamic_policy.rb, line 148
def with_age_derived_attribute(derivation, constraints: nil)
  attribute_builder = WantedAttribute.builder
  attribute_builder.with_name(Attribute::DATE_OF_BIRTH)
  attribute_builder.with_derivation(derivation)
  constraints&.each do |constraint|
    attribute_builder.with_constraint constraint
  end
  with_wanted_attribute(attribute_builder.build)
end
with_age_over(age, options = {}) click to toggle source

@param [Integer] age @option options [Array<SourceConstraint>] :constraints @option options [Bool] :accept_self_asserted

# File lib/yoti/dynamic_share_service/policy/dynamic_policy.rb, line 163
def with_age_over(age, options = {})
  with_age_derived_attribute(Attribute::AGE_OVER + age.to_s, **options)
end
with_age_under(age, options = {}) click to toggle source

@param [Integer] age @option options [Array<SourceConstraint>] :constraints @option options [Bool] :accept_self_asserted

# File lib/yoti/dynamic_share_service/policy/dynamic_policy.rb, line 172
def with_age_under(age, options = {})
  with_age_derived_attribute(Attribute::AGE_UNDER + age.to_s, **options)
end
with_date_of_birth(options = {}) click to toggle source

@option options [Array<SourceConstraint>] :constraints @option options [Bool] :accept_self_asserted

# File lib/yoti/dynamic_share_service/policy/dynamic_policy.rb, line 140
def with_date_of_birth(options = {})
  with_wanted_attribute_by_name Attribute::DATE_OF_BIRTH, **options
end
with_document_details(options = {}) click to toggle source

@option options [Array<SourceConstraint>] :constraints @option options [Bool] :accept_self_asserted

# File lib/yoti/dynamic_share_service/policy/dynamic_policy.rb, line 236
def with_document_details(options = {})
  with_wanted_attribute_by_name(Attribute::DOCUMENT_DETAILS, **options)
end
with_document_images(options = {}) click to toggle source

@option options [Array<SourceConstraint>] :constraints @option options [Bool] :accept_self_asserted

# File lib/yoti/dynamic_share_service/policy/dynamic_policy.rb, line 244
def with_document_images(options = {})
  with_wanted_attribute_by_name(Attribute::DOCUMENT_IMAGES, **options)
end
with_email(options = {}) click to toggle source

@option options [Array<SourceConstraint>] :constraints @option options [Bool] :accept_self_asserted

# File lib/yoti/dynamic_share_service/policy/dynamic_policy.rb, line 228
def with_email(options = {})
  with_wanted_attribute_by_name(Attribute::EMAIL_ADDRESS, **options)
end
with_family_name(options = {}) click to toggle source

@option options [Array<SourceConstraint>] :constraints @option options [Bool] :accept_self_asserted

# File lib/yoti/dynamic_share_service/policy/dynamic_policy.rb, line 116
def with_family_name(options = {})
  with_wanted_attribute_by_name Attribute::FAMILY_NAME, **options
end
with_full_name(options = {}) click to toggle source

@option options [Array<SourceConstraint>] :constraints @option options [Bool] :accept_self_asserted

# File lib/yoti/dynamic_share_service/policy/dynamic_policy.rb, line 132
def with_full_name(options = {})
  with_wanted_attribute_by_name Attribute::FULL_NAME, **options
end
with_gender(options = {}) click to toggle source

@option options [Array<SourceConstraint>] :constraints @option options [Bool] :accept_self_asserted

# File lib/yoti/dynamic_share_service/policy/dynamic_policy.rb, line 180
def with_gender(options = {})
  with_wanted_attribute_by_name Attribute::GENDER, **options
end
with_given_names(options = {}) click to toggle source

@option options [Array<SourceConstraint>] :constraints @option options [Bool] :accept_self_asserted

# File lib/yoti/dynamic_share_service/policy/dynamic_policy.rb, line 124
def with_given_names(options = {})
  with_wanted_attribute_by_name Attribute::GIVEN_NAMES, **options
end
with_nationality(options = {}) click to toggle source

@option options [Array<SourceConstraint>] :constraints @option options [Bool] :accept_self_asserted

# File lib/yoti/dynamic_share_service/policy/dynamic_policy.rb, line 204
def with_nationality(options = {})
  with_wanted_attribute_by_name(Attribute::NATIONALITY, **options)
end
with_phone_number(options = {}) click to toggle source

@option options [Array<SourceConstraint>] :constraints @option options [Bool] :accept_self_asserted

# File lib/yoti/dynamic_share_service/policy/dynamic_policy.rb, line 212
def with_phone_number(options = {})
  with_wanted_attribute_by_name(Attribute::PHONE_NUMBER, **options)
end
with_pin_auth(wanted = true) click to toggle source

@param [Bool] wanted

# File lib/yoti/dynamic_share_service/policy/dynamic_policy.rb, line 84
def with_pin_auth(wanted = true)
  with_wanted_auth_type(DynamicPolicy::PIN_AUTH_TYPE, wanted)
end
with_postal_address(options = {}) click to toggle source

@option options [Array<SourceConstraint>] :constraints @option options [Bool] :accept_self_asserted

# File lib/yoti/dynamic_share_service/policy/dynamic_policy.rb, line 188
def with_postal_address(options = {})
  with_wanted_attribute_by_name(Attribute::POSTAL_ADDRESS, **options)
end
with_selfie(options = {}) click to toggle source

@option options [Array<SourceConstraint>] :constraints @option options [Bool] :accept_self_asserted

# File lib/yoti/dynamic_share_service/policy/dynamic_policy.rb, line 220
def with_selfie(options = {})
  with_wanted_attribute_by_name(Attribute::SELFIE, **options)
end
with_selfie_auth(wanted = true) click to toggle source

@param [Bool] wanted

# File lib/yoti/dynamic_share_service/policy/dynamic_policy.rb, line 77
def with_selfie_auth(wanted = true)
  with_wanted_auth_type(DynamicPolicy::SELFIE_AUTH_TYPE, wanted)
end
with_structured_postal_address(options = {}) click to toggle source

@option options [Array<SourceConstraint>] :constraints @option options [Bool] :accept_self_asserted

# File lib/yoti/dynamic_share_service/policy/dynamic_policy.rb, line 196
def with_structured_postal_address(options = {})
  with_wanted_attribute_by_name(Attribute::STRUCTURED_POSTAL_ADDRESS, **options)
end
with_wanted_attribute(attribute) click to toggle source

@param [Yoti::DynamicSharingService::WantedAttribute] attribute

# File lib/yoti/dynamic_share_service/policy/dynamic_policy.rb, line 91
def with_wanted_attribute(attribute)
  key = attribute.derivation || attribute.name
  @wanted_attributes[key] = attribute
  self
end
with_wanted_attribute_by_name(name, constraints: nil, accept_self_asserted: nil) click to toggle source

@param [String] name @param [Array<SourceConstraint>] constraints @param [Bool] accept_self_asserted

# File lib/yoti/dynamic_share_service/policy/dynamic_policy.rb, line 102
def with_wanted_attribute_by_name(name, constraints: nil, accept_self_asserted: nil)
  attribute_builder = WantedAttribute.builder.with_name(name)
  constraints&.each do |constraint|
    attribute_builder.with_constraint constraint
  end
  attribute_builder.with_accept_self_asserted(accept_self_asserted) unless accept_self_asserted.nil?
  attribute = attribute_builder.build
  with_wanted_attribute attribute
end
with_wanted_auth_type(auth, wanted = true) click to toggle source

@param [Integer] auth @param [Bool] wanted

# File lib/yoti/dynamic_share_service/policy/dynamic_policy.rb, line 69
def with_wanted_auth_type(auth, wanted = true)
  @wanted_auth_types[auth] = wanted
  self
end
with_wanted_remember_me(wanted = true) click to toggle source

@param [Bool] wanted

# File lib/yoti/dynamic_share_service/policy/dynamic_policy.rb, line 60
def with_wanted_remember_me(wanted = true)
  @policy.instance_variable_set(:@wanted_remember_me, wanted)
  self
end