Module: Swipecardable

Included in:
User
Defined in:
app/models/swipecardable.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object


17
18
19
20
21
22
23
24
25
# File 'app/models/swipecardable.rb', line 17

def self.included(base)
  base.class_eval do
    def self.encrypt_swipecard_code(code)
      User.encrypt(code, nil)
    end
    # won't work, because of the salt.
    scope :with_swipecard_code, ->(*swipecard_codes) { where(encrypted_swipecard_code: swipecard_codes.flatten.map { |sw| encrypt_swipecard_code(sw) }) }
  end
end

Instance Method Details

#compare_swipecard_code(code) ⇒ Object


13
14
15
# File 'app/models/swipecardable.rb', line 13

def compare_swipecard_code(code)
  User.encrypt_swipecard_code(code) == encrypted_swipecard_code
end

#swipecard_codeObject


6
7
# File 'app/models/swipecardable.rb', line 6

def swipecard_code
end

#swipecard_code=(code) ⇒ Object


2
3
4
# File 'app/models/swipecardable.rb', line 2

def swipecard_code=(code)
  self.encrypted_swipecard_code = User.encrypt_swipecard_code(code)
end

#swipecard_code?Boolean

Returns:

  • (Boolean)

9
10
11
# File 'app/models/swipecardable.rb', line 9

def swipecard_code?
  encrypted_swipecard_code?
end