Class: Yoti::DynamicSharingService::DynamicPolicyBuilder
- Inherits:
-
Object
- Object
- Yoti::DynamicSharingService::DynamicPolicyBuilder
- Defined in:
- lib/yoti/dynamic_share_service/policy/dynamic_policy.rb
Overview
Builder for DynamicPolicy
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize ⇒ DynamicPolicyBuilder
constructor
A new instance of DynamicPolicyBuilder.
- #with_age_derived_attribute(derivation, constraints: nil) ⇒ Object
- #with_age_over(age, options = {}) ⇒ Object
- #with_age_under(age, options = {}) ⇒ Object
- #with_date_of_birth(options = {}) ⇒ Object
- #with_document_details ⇒ Object
- #with_email(options = {}) ⇒ Object
- #with_family_name(options = {}) ⇒ Object
- #with_full_name(options = {}) ⇒ Object
- #with_gender(options = {}) ⇒ Object
- #with_given_names(options = {}) ⇒ Object
- #with_nationality(options = {}) ⇒ Object
- #with_phone_number(options = {}) ⇒ Object
- #with_pin_auth(wanted = true) ⇒ Object
- #with_postal_address(options = {}) ⇒ Object
- #with_selfie(options = {}) ⇒ Object
- #with_selfie_auth(wanted = true) ⇒ Object
- #with_structured_postal_address(options = {}) ⇒ Object
- #with_wanted_attribute(attribute) ⇒ Object
- #with_wanted_attribute_by_name(name, constraints: nil) ⇒ Object
- #with_wanted_auth_type(auth, wanted = true) ⇒ Object
- #with_wanted_remember_me(wanted = true) ⇒ Object
Constructor Details
#initialize ⇒ DynamicPolicyBuilder
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
#build ⇒ Object
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
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
140 141 142 |
# File 'lib/yoti/dynamic_share_service/policy/dynamic_policy.rb', line 140 def with_age_over(age, = {}) with_age_derived_attribute(Attribute::AGE_OVER + age.to_s, **) end |
#with_age_under(age, options = {}) ⇒ Object
147 148 149 |
# File 'lib/yoti/dynamic_share_service/policy/dynamic_policy.rb', line 147 def with_age_under(age, = {}) with_age_derived_attribute(Attribute::AGE_UNDER + age.to_s, **) 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( = {}) with_wanted_attribute_by_name Attribute::DATE_OF_BIRTH, ** end |
#with_document_details ⇒ Object
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( = {}) with_wanted_attribute_by_name(Attribute::EMAIL_ADDRESS, **) 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( = {}) with_wanted_attribute_by_name Attribute::FAMILY_NAME, ** 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( = {}) with_wanted_attribute_by_name Attribute::FULL_NAME, ** end |
#with_gender(options = {}) ⇒ Object
151 152 153 |
# File 'lib/yoti/dynamic_share_service/policy/dynamic_policy.rb', line 151 def with_gender( = {}) with_wanted_attribute_by_name Attribute::GENDER, ** 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( = {}) with_wanted_attribute_by_name Attribute::GIVEN_NAMES, ** end |
#with_nationality(options = {}) ⇒ Object
163 164 165 |
# File 'lib/yoti/dynamic_share_service/policy/dynamic_policy.rb', line 163 def with_nationality( = {}) with_wanted_attribute_by_name(Attribute::NATIONALITY, **) 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( = {}) with_wanted_attribute_by_name(Attribute::PHONE_NUMBER, **) end |
#with_pin_auth(wanted = true) ⇒ Object
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( = {}) with_wanted_attribute_by_name(Attribute::POSTAL_ADDRESS, **) end |
#with_selfie(options = {}) ⇒ Object
171 172 173 |
# File 'lib/yoti/dynamic_share_service/policy/dynamic_policy.rb', line 171 def with_selfie( = {}) with_wanted_attribute_by_name(Attribute::SELFIE, **) end |
#with_selfie_auth(wanted = true) ⇒ Object
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( = {}) with_wanted_attribute_by_name(Attribute::STRUCTURED_POSTAL_ADDRESS, **) 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
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
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
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 |