Class: Munificent::Donator
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Munificent::Donator
- Includes:
- Authenticable
- Defined in:
- app/models/munificent/donator.rb
Instance Attribute Summary collapse
-
#password_confirmation ⇒ Object
Returns the value of attribute password_confirmation.
-
#require_password ⇒ Object
writeonly
Sets the attribute require_password.
Class Method Summary collapse
Instance Method Summary collapse
- #anonymous? ⇒ Boolean
- #confirm ⇒ Object
- #display_name(current_donator: nil) ⇒ Object
- #email_address=(new_email_address) ⇒ Object
- #no_identifying_marks? ⇒ Boolean
- #require_password? ⇒ Boolean
- #token ⇒ Object
- #token_with_email_address ⇒ Object
- #total_donations(fundraiser: nil) ⇒ Object
- #twitch_connected? ⇒ Boolean
Methods inherited from ApplicationRecord
Instance Attribute Details
#password_confirmation ⇒ Object
Returns the value of attribute password_confirmation.
7 8 9 |
# File 'app/models/munificent/donator.rb', line 7 def password_confirmation @password_confirmation end |
#require_password=(value) ⇒ Object (writeonly)
Sets the attribute require_password
8 9 10 |
# File 'app/models/munificent/donator.rb', line 8 def require_password=(value) @require_password = value end |
Class Method Details
.create_from_omniauth!(auth_hash) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/models/munificent/donator.rb', line 45 def self.create_from_omniauth!(auth_hash) case (provider = auth_hash["provider"]) when "twitch" Donator.create!( chosen_name: auth_hash.dig("info", "nickname"), email_address: auth_hash.dig("info", "email"), name: auth_hash.dig("info", "name"), twitch_id: auth_hash["uid"], ) else raise "Unsupported provider: #{provider}" end end |
Instance Method Details
#anonymous? ⇒ Boolean
90 91 92 |
# File 'app/models/munificent/donator.rb', line 90 def anonymous? name.blank? && chosen_name.blank? end |
#confirm ⇒ Object
102 103 104 105 106 107 108 109 110 |
# File 'app/models/munificent/donator.rb', line 102 def confirm return unless confirmed? || unconfirmed_email_address.present? update( confirmed: true, email_address: unconfirmed_email_address, unconfirmed_email_address: nil, ) end |
#display_name(current_donator: nil) ⇒ Object
84 85 86 87 88 |
# File 'app/models/munificent/donator.rb', line 84 def display_name(current_donator: nil) return I18n.t("common.abstract.you") if current_donator == self chosen_name.presence || name.presence || I18n.t("common.abstract.anonymous") end |
#email_address=(new_email_address) ⇒ Object
59 60 61 62 |
# File 'app/models/munificent/donator.rb', line 59 def email_address=(new_email_address) super(new_email_address.presence) @token_with_email_address = nil end |
#no_identifying_marks? ⇒ Boolean
98 99 100 |
# File 'app/models/munificent/donator.rb', line 98 def email_address.blank? && twitch_id.blank? end |
#require_password? ⇒ Boolean
10 11 12 |
# File 'app/models/munificent/donator.rb', line 10 def require_password? !!@require_password end |
#token ⇒ Object
72 73 74 75 76 |
# File 'app/models/munificent/donator.rb', line 72 def token @token ||= HMAC::Generator .new(context: "sessions") .generate(id:) end |
#token_with_email_address ⇒ Object
78 79 80 81 82 |
# File 'app/models/munificent/donator.rb', line 78 def token_with_email_address @token_with_email_address ||= HMAC::Generator .new(context: "sessions") .generate(id:, extra_fields: { email_address: }) end |
#total_donations(fundraiser: nil) ⇒ Object
64 65 66 67 68 69 70 |
# File 'app/models/munificent/donator.rb', line 64 def total_donations(fundraiser: nil) if fundraiser donations.where(fundraiser:) else donations end.map(&:amount).reduce(Money.new(0), :+) end |
#twitch_connected? ⇒ Boolean
94 95 96 |
# File 'app/models/munificent/donator.rb', line 94 def twitch_connected? twitch_id.present? end |