macker 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6aa439c52993c14e5555b66285280b137d9b8c95
4
- data.tar.gz: 0e2b2b93e03f29b3e7a5cc5eb017e98295a2355b
3
+ metadata.gz: ea5d1e1ff7f91eef4e7bca6bf77f48dc7d81056f
4
+ data.tar.gz: e22dcdbf13329e83ac29836c1d182d9f68d84f88
5
5
  SHA512:
6
- metadata.gz: 7b76f5513fb2617a47939307872afef96e3207643acae2c662930f9cfdb60fa9997d16be4489f6f6d6cc59923f70528031162f9a9cac227412cf4795a4852a09
7
- data.tar.gz: 9e2690473284226b08e6519cdb27498c4e21e790966707910bad0acfd23741fb8097ea33a4c35ef6797a053c50a1a19ef26a93cbc67faf68ff520e00edfdd332
6
+ metadata.gz: 17fabf1c334ac6e68c1b9ad5f854c58c165d7671a0837c7fb437e82563353fb22898384c088f04d7e907c24d1453f3772d47ad2de5ddc76c0ccde740c0eba776
7
+ data.tar.gz: f34c606101a3bf655996d27bdafe9c96e2f28b617a325135e17a02997f07fecab6513c7e8268da5388d651f1c92d9ee39dcc6d38ee772ed664c3c5743b8e384e
data/README.md CHANGED
@@ -48,7 +48,8 @@ Macker.configure do |config|
48
48
  config.user_agent = 'Mozilla/5.0 (X11; Linux x86_64; rv:54.0) Gecko/20100101 Firefox/54.0' # A common user agent
49
49
  config.ttl_in_seconds = 86_400 # Will expire the vendors in one day
50
50
  config.cache = File.expand_path(File.dirname(__FILE__) + '/../../data/oui_*.txt') # Can be a string, pathname or proc
51
- config.auto_expiration = true # Expiration can be checked manually
51
+ config.auto_expire = true # Expiration can be checked manually
52
+ config.auto_stale = true # Stale can be checked manually
52
53
  end
53
54
  ```
54
55
 
@@ -156,9 +157,15 @@ Macker.iso_code_table
156
157
  Macker.vendor_table
157
158
  # => "Apple, Inc."=>[{:prefix=>...} ... ]
158
159
 
160
+ Macker.lapsed!
161
+ # => false
162
+
159
163
  Macker.expire!
160
164
  # => false
161
165
 
166
+ Macker.stale!
167
+ # => false
168
+
162
169
  Macker.expired?
163
170
  # => false
164
171
 
@@ -66,7 +66,7 @@ module Macker
66
66
  # @param opts [Hash] options for the method
67
67
  # @return [Address] MAC address with vendor data
68
68
  def lookup(mac, opts = {})
69
- expire! if config.auto_expiration
69
+ lapsed!
70
70
  data = prefix_table[Address.new(mac).prefix]
71
71
  if data.nil?
72
72
  opts[:raising] ? raise(NotFoundOuiVendor, "OUI not found for MAC: #{mac}") : (return nil)
@@ -100,7 +100,7 @@ module Macker
100
100
  # @param opts [Hash] options for the method
101
101
  # @return [Address] MAC address with data
102
102
  def generate(opts = {})
103
- expire! if config.auto_expiration
103
+ lapsed!
104
104
  return generate_by_iso_code(opts.delete(:iso_code).upcase, opts) if opts[:iso_code]
105
105
  vendor = opts.delete(:vendor)
106
106
  case vendor
@@ -153,13 +153,35 @@ module Macker
153
153
  @vendor_table
154
154
  end
155
155
 
156
- # Fetch new vendor list if cached list is expired or stale
156
+ # Fetch new vendor list if cached list is lapsed (expired or stale)
157
+ # @return [Boolean] true if vendor list is lapsed and updated
158
+ def lapsed!
159
+ if config.auto_expire && expired?
160
+ update(true)
161
+ true
162
+ elsif config.auto_stale && stale?
163
+ update
164
+ true
165
+ else
166
+ false
167
+ end
168
+ end
169
+
170
+ # Fetch new vendor list if cached list is expired
157
171
  # @return [Boolean] true if vendor list is expired and updated from remote
158
172
  def expire!
159
173
  if expired?
160
174
  update(true)
161
175
  true
162
- elsif stale?
176
+ else
177
+ false
178
+ end
179
+ end
180
+
181
+ # Fetch new vendor list if cached list is stale
182
+ # @return [Boolean] true if vendor list is stale and updated from cache
183
+ def stale!
184
+ if stale?
163
185
  update
164
186
  true
165
187
  else
@@ -16,7 +16,9 @@ module Macker
16
16
  # Can be a string, pathname or proc
17
17
  cache: File.expand_path(File.dirname(__FILE__) + '/../../data/oui_*.txt'),
18
18
  # Expiration can be checked manually
19
- auto_expiration: true
19
+ auto_expire: true,
20
+ # Stale can be checked manually
21
+ auto_stale: true
20
22
  )
21
23
  end
22
24
 
@@ -3,5 +3,5 @@
3
3
  # Macker namespace
4
4
  module Macker
5
5
  # Macker version
6
- VERSION = '0.1.4'.freeze
6
+ VERSION = '0.1.5'.freeze
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: macker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Egon Zemmer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-25 00:00:00.000000000 Z
11
+ date: 2017-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake