Skip to content

Commit

Permalink
Merge pull request #116 from k1LoW/adjust-rubocop
Browse files Browse the repository at this point in the history
Adjust rubocop.
  • Loading branch information
k1LoW committed Feb 3, 2016
2 parents c1093b3 + ad2a9b0 commit 8ee0eaf
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 34 deletions.
15 changes: 15 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
AllCops:
TargetRubyVersion: 2.1

Lint/Eval:
Enabled: false

Expand Down Expand Up @@ -25,6 +28,12 @@ Metrics/MethodLength:
Metrics/PerceivedComplexity:
Max: 15

Performance/StringReplacement:
Enabled: false

Style/Alias:
Enabled: false

Style/BarePercentLiterals:
Enabled: false

Expand All @@ -34,6 +43,12 @@ Style/ClassAndModuleChildren:
Style/Documentation:
Enabled: false

Style/MutableConstant:
Enabled: false

Style/MultilineOperationIndentation:
Enabled: false

Style/StabbyLambdaParentheses:
Enabled: false

Expand Down
1 change: 0 additions & 1 deletion lib/awspec/generator/spec/elb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ def generate_by_vpc_id(vpc_id)
specs.join("\n")
end

# rubocop:disable all
def elb_spec_template
template = <<-'EOF'
describe elb('<%= lb.load_balancer_name %>') do
Expand Down
20 changes: 10 additions & 10 deletions lib/awspec/generator/spec/network_acl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ def generate_subnet_specs(acl)
specs = []
acl.associations.each do |a|
subnet = find_subnet(a.subnet_id)
if subnet.tag_name
spec = "it { should have_subnet('" + subnet.tag_name + "') }"
else
spec = "it { should have_subnet('" + subnet.subnet_id + "') }"
end
spec = if subnet.tag_name
"it { should have_subnet('" + subnet.tag_name + "') }"
else
"it { should have_subnet('" + subnet.subnet_id + "') }"
end
specs.push(spec)
end
specs
Expand All @@ -52,11 +52,11 @@ def generate_linespecs(acl)
line += ' ' + actions[entry.rule_action.to_sym]
port_range = entry.port_range
unless port_range.nil?
if port_range.from == port_range.to
port = port_range.from.to_s
else
port = "'" + port_range.from.to_s + '-' + port_range.to.to_s + "'"
end
port = if port_range.from == port_range.to
port_range.from.to_s
else
"'" + port_range.from.to_s + '-' + port_range.to.to_s + "'"
end
line += '(' + port + ')'
end
line += ".protocol('" + protocols[entry.protocol.to_i] + "')"
Expand Down
3 changes: 1 addition & 2 deletions lib/awspec/generator/spec/route53_hosted_zone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,15 @@ def generate_linespec(record_set)
EOF
v = record_set.resource_records.map { |r| r.value }.join("\n")
type = record_set.type.downcase
return ERB.new(template, nil, '-').result(binding)
else
# ALIAS
dns_name = record_set.alias_target.dns_name
hosted_zone_id = record_set.alias_target.hosted_zone_id
template = <<-'EOF'
it { should have_record_set('<%= name %>').alias('<%= dns_name %>', '<%= hosted_zone_id %>') }
EOF
return ERB.new(template, nil, '-').result(binding)
end
ERB.new(template, nil, '-').result(binding)
end

def route53_hosted_zone_spec_template
Expand Down
2 changes: 0 additions & 2 deletions lib/awspec/generator/spec/route_table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ def route_table_spec_instance_linetemplate
template
end

# rubocop:disable Metrics/LineLength
def route_table_spec_connection_linetemplate
template = <<-'EOF'
<%- if connection.tag_name -%>
Expand All @@ -78,7 +77,6 @@ def route_table_spec_connection_linetemplate
EOF
template
end
# rubocop:enable Metrics/LineLength

def route_table_spec_nat_linetemplate
template = <<-'EOF'
Expand Down
10 changes: 5 additions & 5 deletions lib/awspec/generator/spec/security_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ def generate_linespecs(sg)
next
end

if permission.from_port == permission.to_port
port = permission.from_port
else
port = "'" + permission.from_port.to_s + '-' + permission.to_port.to_s + "'"
end
port = if permission.from_port == permission.to_port
permission.from_port
else
"'" + permission.from_port.to_s + '-' + permission.to_port.to_s + "'"
end

protocol = permission.ip_protocol
permission.ip_ranges.each do |ip_range|
Expand Down
2 changes: 2 additions & 0 deletions lib/awspec/helper/finder/ec2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module Awspec::Helper
module Finder
module Ec2
def find_ec2(id)
# rubocop:disable Style/GuardClause
if id.is_a?(Array)
# Aws::EC2::Client.describe_instances native filters format
res = ec2_client.describe_instances({
Expand Down Expand Up @@ -32,6 +33,7 @@ def find_ec2(id)
else
return nil
end
# rubocop:enable Style/GuardClause
return res[:reservations].first[:instances].first if res[:reservations].count == 1 && \
res[:reservations].first[:instances].count == 1
end
Expand Down
15 changes: 6 additions & 9 deletions lib/awspec/resource_reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@ class CalledMethodInBlackList < StandardError

def method_missing_via_black_list(name, delegate_to: nil)
fail(ArguementError, 'delegate_to: must be specified') unless delegate_to
if match_black_list?(name)
fail CalledMethodInBlackList, "Method call #{name.inspect} is black-listed"
fail CalledMethodInBlackList, "Method call #{name.inspect} is black-listed" if match_black_list?(name)
attr = delegate_to.send(name)
case attr
when Aws::Resources::Resource
ResourceReader.new(attr)
else
attr = delegate_to.send(name)
case attr
when Aws::Resources::Resource
ResourceReader.new(attr)
else
attr
end
attr
end
end

Expand Down
7 changes: 2 additions & 5 deletions lib/awspec/type/security_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@ def initialize(id)
end

def opened?(port = nil, protocol = nil, cidr = nil)
if @inbound
return inbound_opened?(port, protocol, cidr)
else
return outbound_opened?(port, protocol, cidr)
end
return inbound_opened?(port, protocol, cidr) if @inbound
outbound_opened?(port, protocol, cidr)
end

def inbound_opened?(port = nil, protocol = nil, cidr = nil)
Expand Down

0 comments on commit 8ee0eaf

Please sign in to comment.