lint vulcano lib files

Signed-off-by: Dominik Richter <dominik.richter@gmail.com>
This commit is contained in:
Dominik Richter 2015-09-09 16:29:20 +02:00
parent 07cb7efe36
commit 74da29c3ed
4 changed files with 21 additions and 16 deletions

View file

@ -3,7 +3,7 @@
# license: All rights reserved
class VulcanoBaseRule
def initialize(id, opts, &block)
def initialize(id, _opts, &block)
@id = id
@impact = nil
@__code = ''
@ -14,10 +14,10 @@ class VulcanoBaseRule
@profile_id = nil
@checks = []
# evaluate the given definition
self.instance_eval(&block) if block_given?
instance_eval(&block) if block_given?
end
def id(v = nil)
def id(*_)
# never overwrite the ID
@id
end
@ -49,9 +49,9 @@ class VulcanoBaseRule
return
end
# merge all fields
dst.impact(src.impact) if src.impact != nil
dst.title(src.title) if src.title != nil
dst.desc(src.desc) if src.desc != nil
dst.impact(src.impact) unless src.impact.nil?
dst.title(src.title) unless src.title.nil?
dst.desc(src.desc) unless src.desc.nil?
# merge indirect fields
# checks defined in the source will completely eliminate
# all checks that were defined in the destination

View file

@ -13,19 +13,20 @@ module Vulcano
@profile_id = profile_id
@rules = profile_registry
@only_ifs = only_ifs
__CTX = self
profile_context_owner = self
# This is the heart of the profile context
# An instantiated object which has all resources registered to it
# and exposes them to the a test file.
# rubocop:disable Lint/NestedMethodDefinition
ctx = Class.new do
include Vulcano::DSL
define_method :__register_rule do |*args|
__CTX.register_rule(*args)
profile_context_owner.register_rule(*args)
end
define_method :__unregister_rule do |*args|
__CTX.unregister_rule(*args)
profile_context_owner.unregister_rule(*args)
end
Vulcano::Resource.registry.each do |id, r|
@ -38,6 +39,8 @@ module Vulcano
'Profile Context Run'
end
end
# rubocop:enable all
@profile_context = ctx.new
end

View file

@ -17,7 +17,7 @@ module RSpec::Core::Formatters
line_number: example.metadata['line_number'],
run_time: example.execution_result.run_time,
pending_message: example.execution_result.pending_message,
id: example.metadata[:id]
id: example.metadata[:id],
}
end
end

View file

@ -33,7 +33,7 @@ module Vulcano::DSL
line = block.source_location[1]
id = "#{File.basename(path)}:#{line}"
rule = Vulcano::Rule.new(id, {}) do
describe *args, &block
describe(*args, &block)
end
__register_rule rule, &block
end
@ -44,7 +44,7 @@ module Vulcano::DSL
def only_if(&block)
return unless block_given?
@skip_profile = !block.()
@skip_profile = !block.call
end
def require_rules(id, &block)
@ -95,7 +95,7 @@ module Vulcano::DSL
ex.metadata[:id] = id
}
obj.children.each {|c|
self.set_rspec_ids(c, id)
set_rspec_ids(c, id)
}
end
@ -146,7 +146,7 @@ module Vulcano::DSL
end
# finally register all combined rules
rule_registry.each do |id, rule|
rule_registry.each do |_id, rule|
bind_context.__register_rule rule
end
end
@ -166,7 +166,6 @@ module Vulcano::DSL
end
files
end
end
module Vulcano::GlobalDSL
@ -174,12 +173,14 @@ module Vulcano::GlobalDSL
# make sure the profile id is attached to the rule
::Vulcano::DSL.execute_rule(r, __profile_id)
end
def __unregister_rule(id)
def __unregister_rule(_id)
end
end
module Vulcano::DSLHelper
def self.bind_dsl(scope)
# rubocop:disable Lint/NestedMethodDefinition
(class << scope; self; end).class_exec do
include Vulcano::DSL
include Vulcano::GlobalDSL
@ -187,6 +188,7 @@ module Vulcano::DSLHelper
ENV['VULCANOSEC_PROFILE_ID']
end
end
# rubocop:enable all
end
end