Skip to content

Commit

Permalink
Bump to version 0.1.5.
Browse files Browse the repository at this point in the history
  • Loading branch information
phlegx committed Jul 26, 2017
1 parent 98e65a5 commit c1926c5
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ Macker.configure do |config|
config.user_agent = 'Mozilla/5.0 (X11; Linux x86_64; rv:54.0) Gecko/20100101 Firefox/54.0' # A common user agent
config.ttl_in_seconds = 86_400 # Will expire the vendors in one day
config.cache = File.expand_path(File.dirname(__FILE__) + '/../../data/oui_*.txt') # Can be a string, pathname or proc
config.auto_expiration = true # Expiration can be checked manually
config.auto_expire = true # Expiration can be checked manually
config.auto_stale = true # Stale can be checked manually
end
```

Expand Down Expand Up @@ -156,9 +157,15 @@ Macker.iso_code_table
Macker.vendor_table
# => "Apple, Inc."=>[{:prefix=>...} ... ]

Macker.lapsed!
# => false

Macker.expire!
# => false

Macker.stale!
# => false

Macker.expired?
# => false

Expand Down
30 changes: 26 additions & 4 deletions lib/macker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def update(straight = false)
# @param opts [Hash] options for the method
# @return [Address] MAC address with vendor data
def lookup(mac, opts = {})
expire! if config.auto_expiration
lapsed!
data = prefix_table[Address.new(mac).prefix]
if data.nil?
opts[:raising] ? raise(NotFoundOuiVendor, "OUI not found for MAC: #{mac}") : (return nil)
Expand Down Expand Up @@ -100,7 +100,7 @@ def lookup!(mac)
# @param opts [Hash] options for the method
# @return [Address] MAC address with data
def generate(opts = {})
expire! if config.auto_expiration
lapsed!
return generate_by_iso_code(opts.delete(:iso_code).upcase, opts) if opts[:iso_code]
vendor = opts.delete(:vendor)
case vendor
Expand Down Expand Up @@ -153,13 +153,35 @@ def vendor_table
@vendor_table
end

# Fetch new vendor list if cached list is expired or stale
# Fetch new vendor list if cached list is lapsed (expired or stale)
# @return [Boolean] true if vendor list is lapsed and updated
def lapsed!
if config.auto_expire && expired?
update(true)
true
elsif config.auto_stale && stale?
update
true
else
false
end
end

# Fetch new vendor list if cached list is expired
# @return [Boolean] true if vendor list is expired and updated from remote
def expire!
if expired?
update(true)
true
elsif stale?
else
false
end
end

# Fetch new vendor list if cached list is stale
# @return [Boolean] true if vendor list is stale and updated from cache
def stale!
if stale?
update
true
else
Expand Down
2 changes: 1 addition & 1 deletion lib/macker/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
# Macker namespace
module Macker
# Macker version
VERSION = '0.1.4'.freeze
VERSION = '0.1.5'.freeze
end

0 comments on commit c1926c5

Please sign in to comment.