Skip to content

Commit

Permalink
Make rubocop happier
Browse files Browse the repository at this point in the history
  • Loading branch information
ananace committed Jun 4, 2018
1 parent 64298f8 commit 1a74b69
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
21 changes: 21 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Metrics/ClassLength:
Exclude:
- 'test/**/*'

Metrics/AbcSize:
Enabled: false

Metrics/BlockLength:
Enabled: false

Metrics/LineLength:
Max: 140

Metrics/MethodLength:
Enabled: false

Metrics/ParameterLists:
Max: 8

Style/ClassAndModuleChildren:
Enabled: false
20 changes: 10 additions & 10 deletions lib/smart_proxy_dhcp_dnsmasq/dhcp_dnsmasq_subnet_service.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'ipaddr'
#require 'rb-inotify'
# require 'rb-inotify'
require 'dhcp_common/dhcp_common'
require 'dhcp_common/subnet_service'
require 'smart_proxy_dhcp_dnsmasq/dhcp_dnsmasq_utils'
Expand All @@ -21,7 +21,7 @@ def initialize(config, target_dir, lease_file, leases_by_ip, leases_by_mac, rese
def load!
parse_config_for_subnets.each { |subnet| add_subnet(subnet) }
load_subnet_data
#add_watch # TODO
# add_watch # TODO

true
end
Expand Down Expand Up @@ -57,7 +57,7 @@ def parse_config_for_subnets
logger.debug "Starting parse of DHCP subnets from #{files}"
files.each do |file|
logger.debug "Parsing #{file}..."
open(file, 'r').each_line.with_index do |line, line_nr|
File.open(file, 'r').each_line.with_index do |line, line_nr|
line.strip!
next if line.empty? || line.start_with?('#') || !line.include?('=')

Expand Down Expand Up @@ -231,7 +231,7 @@ def parse_config_for_dhcp_reservations
dhcpopts_path = File.join(@target_dir, 'dhcpopts.conf')
logger.debug "Parsing DHCP options from #{dhcpopts_path}"
if File.exist? dhcpopts_path
open(dhcpopts_path, 'r').each_line do |line|
File.open(dhcpopts_path, 'r').each_line do |line|
data = line.strip.split(',')
next if data.empty? || !data.first.start_with?('tag:')

Expand All @@ -243,14 +243,14 @@ def parse_config_for_dhcp_reservations
logger.debug "Parsing provisioned DHCP reservations from #{@target_dir}"
Dir[File.join(@target_dir, 'dhcphosts', '*')].each do |file|
logger.debug " Parsing #{file}..."
open(file, 'r').each_line do |line|
File.open(file, 'r').each_line do |line|
data = line.strip.split(',')
next if data.empty? || data.first.start_with?('#')

mac = data.first
data.shift

options = { :deletable => true }
options = { deletable: true }
tags = Proxy::DHCP::Dnsmasq.parse_tags(data)
tags.sets.each do |tag|
value = dhcpoptions[tag]
Expand Down Expand Up @@ -278,7 +278,7 @@ def parse_config_for_dhcp_reservations
def load_subnet_data
reservations = parse_config_for_dhcp_reservations
reservations.each do |record|
if dupe = find_host_by_mac(record.subnet_address, record.mac)
if (dupe = find_host_by_mac(record.subnet_address, record.mac))
logger.debug "Found duplicate #{dupe} when adding record #{record}, skipping"
next
end
Expand All @@ -289,11 +289,11 @@ def load_subnet_data

leases = load_leases
leases.each do |lease|
if dupe = find_lease_by_mac(lease.subnet_address, lease.mac)
if (dupe = find_lease_by_mac(lease.subnet_address, lease.mac))
logger.debug "Found duplicate #{dupe} by MAC when adding lease #{lease}, skipping"
next
end
if dupe = find_lease_by_ip(lease.subnet_address, lease.ip)
if (dupe = find_lease_by_ip(lease.subnet_address, lease.ip))
logger.debug "Found duplicate #{dupe} by IP when adding lease #{lease}, skipping"
next
end
Expand All @@ -305,7 +305,7 @@ def load_subnet_data

# Expects subnet_service to have subnet data
def load_leases
open(@lease_file, 'r').readlines.map do |line|
File.open(@lease_file, 'r').readlines.map do |line|
timestamp, mac, ip, _hostname, _client_id = line.split
timestamp = timestamp.to_i

Expand Down

0 comments on commit 1a74b69

Please sign in to comment.