Class: Yoti::DynamicSharingService::DynamicPolicyBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/yoti/dynamic_share_service/policy/dynamic_policy.rb

Overview

Builder for DynamicPolicy

Instance Method Summary collapse

Constructor Details

#initializeDynamicPolicyBuilder

Returns a new instance of DynamicPolicyBuilder.



37
38
39
40
41
# File 'lib/yoti/dynamic_share_service/policy/dynamic_policy.rb', line 37

def initialize
  @policy = DynamicPolicy.new
  @wanted_auth_types = {}
  @wanted_attributes = {}
end

Instance Method Details

#buildObject



43
44
45
46
47
48
49
50
51
52
# File 'lib/yoti/dynamic_share_service/policy/dynamic_policy.rb', line 43

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) ⇒ Object

Parameters:

  • derivation (String)
  • constraints (Hash) (defaults to: nil)


127
128
129
130
131
132
133
134
135
# File 'lib/yoti/dynamic_share_service/policy/dynamic_policy.rb', line 127

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 = {}) ⇒ Object

Parameters:

  • age (Integer)


140
141
142
# File 'lib/yoti/dynamic_share_service/policy/dynamic_policy.rb', line 140

def with_age_over(age, options = {})
  with_age_derived_attribute(Attribute::AGE_OVER + age.to_s, **options)
end

#with_age_under(age, options = {}) ⇒ Object

Parameters:

  • age (Integer)


147
148
149
# File 'lib/yoti/dynamic_share_service/policy/dynamic_policy.rb', line 147

def with_age_under(age, options = {})
  with_age_derived_attribute(Attribute::AGE_UNDER + age.to_s, **options)
end

#with_date_of_birth(options = {}) ⇒ Object



119
120
121
# File 'lib/yoti/dynamic_share_service/policy/dynamic_policy.rb', line 119

def with_date_of_birth(options = {})
  with_wanted_attribute_by_name Attribute::DATE_OF_BIRTH, **options
end

#with_document_detailsObject



179
180
181
# File 'lib/yoti/dynamic_share_service/policy/dynamic_policy.rb', line 179

def with_document_details
  with_wanted_attribute_by_name(Attribute::DOCUMENT_DETAILS)
end

#with_email(options = {}) ⇒ Object



175
176
177
# File 'lib/yoti/dynamic_share_service/policy/dynamic_policy.rb', line 175

def with_email(options = {})
  with_wanted_attribute_by_name(Attribute::EMAIL_ADDRESS, **options)
end

#with_family_name(options = {}) ⇒ Object



107
108
109
# File 'lib/yoti/dynamic_share_service/policy/dynamic_policy.rb', line 107

def with_family_name(options = {})
  with_wanted_attribute_by_name Attribute::FAMILY_NAME, **options
end

#with_full_name(options = {}) ⇒ Object



115
116
117
# File 'lib/yoti/dynamic_share_service/policy/dynamic_policy.rb', line 115

def with_full_name(options = {})
  with_wanted_attribute_by_name Attribute::FULL_NAME, **options
end

#with_gender(options = {}) ⇒ Object



151
152
153
# File 'lib/yoti/dynamic_share_service/policy/dynamic_policy.rb', line 151

def with_gender(options = {})
  with_wanted_attribute_by_name Attribute::GENDER, **options
end

#with_given_names(options = {}) ⇒ Object



111
112
113
# File 'lib/yoti/dynamic_share_service/policy/dynamic_policy.rb', line 111

def with_given_names(options = {})
  with_wanted_attribute_by_name Attribute::GIVEN_NAMES, **options
end

#with_nationality(options = {}) ⇒ Object



163
164
165
# File 'lib/yoti/dynamic_share_service/policy/dynamic_policy.rb', line 163

def with_nationality(options = {})
  with_wanted_attribute_by_name(Attribute::NATIONALITY, **options)
end

#with_phone_number(options = {}) ⇒ Object



167
168
169
# File 'lib/yoti/dynamic_share_service/policy/dynamic_policy.rb', line 167

def with_phone_number(options = {})
  with_wanted_attribute_by_name(Attribute::PHONE_NUMBER, **options)
end

#with_pin_auth(wanted = true) ⇒ Object

Parameters:

  • wanted (Bool) (defaults to: true)


81
82
83
# File 'lib/yoti/dynamic_share_service/policy/dynamic_policy.rb', line 81

def with_pin_auth(wanted = true)
  with_wanted_auth_type(DynamicPolicy::PIN_AUTH_TYPE, wanted)
end

#with_postal_address(options = {}) ⇒ Object



155
156
157
# File 'lib/yoti/dynamic_share_service/policy/dynamic_policy.rb', line 155

def with_postal_address(options = {})
  with_wanted_attribute_by_name(Attribute::POSTAL_ADDRESS, **options)
end

#with_selfie(options = {}) ⇒ Object



171
172
173
# File 'lib/yoti/dynamic_share_service/policy/dynamic_policy.rb', line 171

def with_selfie(options = {})
  with_wanted_attribute_by_name(Attribute::SELFIE, **options)
end

#with_selfie_auth(wanted = true) ⇒ Object

Parameters:

  • wanted (Bool) (defaults to: true)


74
75
76
# File 'lib/yoti/dynamic_share_service/policy/dynamic_policy.rb', line 74

def with_selfie_auth(wanted = true)
  with_wanted_auth_type(DynamicPolicy::SELFIE_AUTH_TYPE, wanted)
end

#with_structured_postal_address(options = {}) ⇒ Object



159
160
161
# File 'lib/yoti/dynamic_share_service/policy/dynamic_policy.rb', line 159

def with_structured_postal_address(options = {})
  with_wanted_attribute_by_name(Attribute::STRUCTURED_POSTAL_ADDRESS, **options)
end

#with_wanted_attribute(attribute) ⇒ Object



88
89
90
91
92
# File 'lib/yoti/dynamic_share_service/policy/dynamic_policy.rb', line 88

def with_wanted_attribute(attribute)
  key = attribute.derivation || attribute.name
  @wanted_attributes[key] = attribute
  self
end

#with_wanted_attribute_by_name(name, constraints: nil) ⇒ Object

Parameters:

  • name (String)
  • constraints (Hash) (defaults to: nil)


98
99
100
101
102
103
104
105
# File 'lib/yoti/dynamic_share_service/policy/dynamic_policy.rb', line 98

def with_wanted_attribute_by_name(name, constraints: nil)
  attribute_builder = WantedAttribute.builder.with_name(name)
  constraints&.each do |constraint|
    attribute_builder.with_constraint constraint
  end
  attribute = attribute_builder.build
  with_wanted_attribute attribute
end

#with_wanted_auth_type(auth, wanted = true) ⇒ Object

Parameters:

  • auth (Integer)
  • wanted (Bool) (defaults to: true)


66
67
68
69
# File 'lib/yoti/dynamic_share_service/policy/dynamic_policy.rb', line 66

def with_wanted_auth_type(auth, wanted = true)
  @wanted_auth_types[auth] = wanted
  self
end

#with_wanted_remember_me(wanted = true) ⇒ Object

Parameters:

  • wanted (Bool) (defaults to: true)


57
58
59
60
# File 'lib/yoti/dynamic_share_service/policy/dynamic_policy.rb', line 57

def with_wanted_remember_me(wanted = true)
  @policy.instance_variable_set(:@wanted_remember_me, wanted)
  self
end