Class: CommandTower::UserAttributes::Modify
- Inherits:
-
ServiceBase
- Object
- ServiceBase
- CommandTower::UserAttributes::Modify
- Defined in:
- app/services/command_tower/user_attributes/modify.rb
Constant Summary collapse
- DEFAULT =
{ verifier_token: [true, false] }
Constants inherited from ServiceBase
ServiceBase::ON_ARGUMENT_VALIDATION
Class Method Summary collapse
-
.assign! ⇒ Object
Gets assigned during configuration phase via lib/command_tower/configuration/user/config.rb.
Instance Method Summary collapse
Methods inherited from ServiceBase
inherited, #internal_validate, #service_base_logging, #validate!
Methods included from ArgumentValidation
Methods included from ServiceLogging
#aletered_message, #class_name, #log, #log_error, #log_info, #log_prefix, #log_warn, #logger, #service_id
Class Method Details
.assign! ⇒ Object
Gets assigned during configuration phase via lib/command_tower/configuration/user/config.rb
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/services/command_tower/user_attributes/modify.rb', line 14 def self.assign! attributes = CommandTower.config.user.default_attributes_for_change + CommandTower.config.user.additional_attributes_for_change one_of(:modify_attribute, required: true) do attributes.uniq.each do |attribute| if = User.attribute_to_type_mapping[attribute] arguments = {} if default = DEFAULT[attribute.to_sym] arguments[:is_one] = default else if allowed_types = [:allowed_types] arguments[:is_one] = allowed_types else arguments[:is_a] = [:ruby_type] end end validate(attribute, **arguments) end end end end |
Instance Method Details
#call ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/services/command_tower/user_attributes/modify.rb', line 36 def call case modify_attribute_key when :email unless email =~ URI::MailTo::EMAIL_REGEXP inline_argument_failure!(errors: { email: "Invalid email address" }) end when :username username_validity = CommandTower::Username::Available.(username:) unless username_validity.valid inline_argument_failure!(errors: { username: "Username is invalid. #{CommandTower.config.username.}" }) end when :verifier_token if verifier_token verifier_token! else inline_argument_failure!(errors: { verifier_token: "verifier_token is invalid. Expected [true] when value present" }) end return end update! end |
#update! ⇒ Object
64 65 66 |
# File 'app/services/command_tower/user_attributes/modify.rb', line 64 def update! user.update!(modify_attribute_key => modify_attribute) end |
#verifier_token! ⇒ Object
60 61 62 |
# File 'app/services/command_tower/user_attributes/modify.rb', line 60 def verifier_token! user.reset_verifier_token! end |