Skip to content

Commit

Permalink
Rubocop fixes (#351)
Browse files Browse the repository at this point in the history
* fallback to included resource spec if not overridden

* rubocop 0.51.0 compliant

* typo

* another typo
  • Loading branch information
kornypoet authored and gergnz committed Nov 3, 2017
1 parent 76cc621 commit f2de438
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 25 deletions.
4 changes: 2 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ Metrics/MethodLength:
Max: 25

# Due to our @Properties style instance names
Style/VariableName:
Naming/VariableName:
Enabled: false

# We are a DSL
Style/MethodName:
Naming/MethodName:
Enabled: false

# Because of the way FnFormat was developed
Expand Down
2 changes: 0 additions & 2 deletions cfndsl.gemspec
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# coding: utf-8

lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'cfndsl/version'
Expand Down
14 changes: 7 additions & 7 deletions lib/cfndsl/orchestration_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def create_array_property_def(resource, pname, pclass)
define_method(method) do |value = nil, &block|
@Properties ||= {}
@Properties[pname] ||= PropertyDefinition.new([])
value = pclass.new unless value
value ||= pclass.new
@Properties[pname].value.push value
value.instance_eval(&block) if block
value
Expand Down Expand Up @@ -138,11 +138,11 @@ def check_resource_refs
invalids = []
@_resource_refs = {}
if @Resources
@Resources.keys.each do |resource|
@Resources.each_key do |resource|
@_resource_refs[resource.to_s] = @Resources[resource].build_references({})
end
@_resource_refs.keys.each do |origin|
@_resource_refs[origin].keys.each do |ref|
@_resource_refs.each_key do |origin|
@_resource_refs[origin].each_key do |ref|
invalids.push "Invalid Reference: Resource #{origin} refers to #{ref}" unless valid_ref?(ref, origin)
end
end
Expand All @@ -154,11 +154,11 @@ def check_output_refs
invalids = []
output_refs = {}
if @Outputs
@Outputs.keys.each do |resource|
@Outputs.each_key do |resource|
output_refs[resource.to_s] = @Outputs[resource].build_references({})
end
output_refs.keys.each do |origin|
output_refs[origin].keys.each do |ref|
output_refs.each_key do |origin|
output_refs[origin].each_key do |ref|
invalids.push "Invalid Reference: Output #{origin} refers to #{ref}" unless valid_ref?(ref)
end
end
Expand Down
10 changes: 5 additions & 5 deletions lib/cfndsl/types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ def self.included(type_def)
type_def.const_set('Types_Internal', types_list)
# Do a little sanity checking - all of the types referenced in Resources
# should be represented in Types
types_list['Resources'].keys.each do |resource_name|
types_list['Resources'].each_key do |resource_name|
resource = types_list['Resources'][resource_name]
resource.values.each do |thing|
thing.values.each do |type|
resource.each_value do |thing|
thing.each_value do |type|
if type.is_a?(Array)
type.each do |inner_type|
puts "unknown type #{inner_type}" unless types_list['Types'].key?(inner_type)
Expand All @@ -36,7 +36,7 @@ def self.included(type_def)
# All of the type values should also be references
types_list['Types'].values do |type|
if type.respond_to?(:values)
type.values.each do |tv|
type.each_value do |tv|
puts "unknown type #{tv}" unless types_list['Types'].key?(tv)
end
end
Expand Down Expand Up @@ -76,7 +76,7 @@ def self.included(type_def)
# We are going to modify the value in some
# way, make sure that we have an array to mess
# with if we start with nothing
existing = instance_variable_set(variable, []) unless existing
existing ||= instance_variable_set(variable, [])

# special case for just a block, no args
if value.nil? && rest.empty? && block
Expand Down
4 changes: 2 additions & 2 deletions lib/cfnlego.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def self.Resources
content = fetch_resource_content
supported_resources = JSON.parse(content)
resources = []
supported_resources['ResourceTypes'].each do |resource, _value|
supported_resources['ResourceTypes'].each_key do |resource|
resources << resource
end
resources
Expand All @@ -35,7 +35,7 @@ def self.run(options)
begin
return Cfnlego::CloudFormation.new(resources).render
rescue RuntimeError => e
$stderr.puts "Error: #{e.message}"
warn "Error: #{e.message}"
end
nil
end
Expand Down
2 changes: 1 addition & 1 deletion lib/cfnlego/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def definition
data = datainput['ResourceTypes']
begin
@definition ||= data[@type]
rescue
rescue RuntimeError
raise "unknown #{@type}, no matching definition found"
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/deep_merge/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def self.deep_merge!(source, dest, options = {})
end
puts "#{di}Returning #{dest.inspect}" if merge_debug
dest
end # deep_merge!
end

# allows deep_merge! to uniformly handle overwriting of unmergeable entities
def self.overwrite_unmergeables(source, dest, options)
Expand Down Expand Up @@ -241,4 +241,4 @@ def self.clear_or_nil(obj)
end
obj
end
end # module DeepMerge
end
2 changes: 1 addition & 1 deletion lib/deep_merge/deep_merge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def deep_merge!(source, options = {})
default_opts = { preserve_unmergeables: false }
DeepMerge.deep_merge!(source, self, default_opts.merge(options))
end
end # DeepMergeHashExt
end
end

# Extends hash with deep merge
Expand Down
4 changes: 2 additions & 2 deletions spec/cfndsl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,11 @@

context 'FnFormat', 'Multiline' do
it 'formats correctly' do
multiline = <<-EOF.gsub(/^ {10}/, '')
multiline = <<-TEXT.gsub(/^ {10}/, '')
This is the first line
This is the %0 line
This is a %% sign
EOF
TEXT
func = subject.FnFormat(multiline, 'second')
expect(func.to_json).to eq('{"Fn::Join":["",["This is the first line\nThis is the ","second"," line\nThis is a ","%"," sign\n"]]}')
end
Expand Down
2 changes: 1 addition & 1 deletion spec/types_definition_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
resources.each do |name, info|
it "#{name} has all property types defined" do
properties = info['Properties']
properties.each do |_, type|
properties.each_value do |type|
type = type.first if type.is_a?(Array)
expect(types).to have_key(type)
end
Expand Down

0 comments on commit f2de438

Please sign in to comment.