Class: Tinypass::AccessTokenList
- Inherits:
-
Object
- Object
- Tinypass::AccessTokenList
- Includes:
- Enumerable
- Defined in:
- lib/tinypass/token/access_token_list.rb
Constant Summary collapse
- MAX =
20
Instance Method Summary collapse
- #<<(token) ⇒ Object (also: #add)
- #[](rid) ⇒ Object
- #add_all(tokens) ⇒ Object
- #delete(rid) ⇒ Object (also: #remove)
- #each(*args, &block) ⇒ Object
- #empty? ⇒ Boolean
- #include?(rid) ⇒ Boolean (also: #contains?)
-
#initialize(input_tokens = nil) ⇒ AccessTokenList
constructor
A new instance of AccessTokenList.
- #length ⇒ Object (also: #size)
- #push(*args) ⇒ Object
- #shift ⇒ Object
- #tokens ⇒ Object (also: #access_tokens)
Constructor Details
#initialize(input_tokens = nil) ⇒ AccessTokenList
Returns a new instance of AccessTokenList.
7 8 9 10 11 12 |
# File 'lib/tinypass/token/access_token_list.rb', line 7 def initialize(input_tokens = nil) @tokens_hash = {} input_tokens = Array(input_tokens) input_tokens.each { |token| self << token } end |
Instance Method Details
#<<(token) ⇒ Object Also known as: add
23 24 25 26 27 28 29 30 |
# File 'lib/tinypass/token/access_token_list.rb', line 23 def <<(token) key = token.token_data.rid @tokens_hash[key] = token shift until size <= MAX self[key] end |
#[](rid) ⇒ Object
19 20 21 |
# File 'lib/tinypass/token/access_token_list.rb', line 19 def [](rid) @tokens_hash[rid.to_s] end |
#add_all(tokens) ⇒ Object
39 40 41 |
# File 'lib/tinypass/token/access_token_list.rb', line 39 def add_all(tokens) self.push(*tokens) end |
#delete(rid) ⇒ Object Also known as: remove
62 63 64 |
# File 'lib/tinypass/token/access_token_list.rb', line 62 def delete(rid) @tokens_hash.delete(rid) end |
#each(*args, &block) ⇒ Object
49 50 51 |
# File 'lib/tinypass/token/access_token_list.rb', line 49 def each(*args, &block) tokens.each(*args, &block) end |
#empty? ⇒ Boolean
58 59 60 |
# File 'lib/tinypass/token/access_token_list.rb', line 58 def empty? @tokens_hash.empty? end |
#include?(rid) ⇒ Boolean Also known as: contains?
43 44 45 46 |
# File 'lib/tinypass/token/access_token_list.rb', line 43 def include?(rid) rid = rid.to_s @tokens_hash.has_key?(rid) end |
#length ⇒ Object Also known as: size
53 54 55 |
# File 'lib/tinypass/token/access_token_list.rb', line 53 def length tokens.size end |
#push(*args) ⇒ Object
33 34 35 36 37 |
# File 'lib/tinypass/token/access_token_list.rb', line 33 def push(*args) args.each do |token| self << token end end |
#shift ⇒ Object
67 68 69 |
# File 'lib/tinypass/token/access_token_list.rb', line 67 def shift delete(@tokens_hash.keys.first) end |
#tokens ⇒ Object Also known as: access_tokens
14 15 16 |
# File 'lib/tinypass/token/access_token_list.rb', line 14 def tokens @tokens_hash.values end |