Speed up (#68)

* Remove `require_all`
* Move rspec options to .rspec
This commit is contained in:
david942j 2019-03-07 13:46:47 +08:00 committed by GitHub
parent a8f15f00e8
commit 4161f18cc7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 9 deletions

4
.rspec Normal file
View File

@ -0,0 +1,4 @@
--color
--order rand
--require spec_helper
--warning

View File

@ -14,10 +14,7 @@ RuboCop::RakeTask.new(:rubocop) do |task|
task.options += ['--force-exclusion', 'lib/one_gadget/builds/*.rb']
end
RSpec::Core::RakeTask.new(:spec) do |task|
task.pattern = './spec/**/*_spec.rb'
task.rspec_opts = ['--color', '--require spec_helper', '--order rand', '--warning']
end
RSpec::Core::RakeTask.new(:spec)
YARD::Rake::YardocTask.new(:doc) do |t|
t.files = Dir['lib/**/*.rb'] - Dir['lib/one_gadget/builds/*.rb']

View File

@ -81,7 +81,7 @@ module OneGadget
module ClassMethods
# Path to the pre-build files.
BUILDS_PATH = File.join(__dir__, 'builds').freeze
# Cache.
# Record.
BUILDS = Hash.new { |h, k| h[k] = [] }
# Get gadgets from pre-defined corpus.
# @param [String] build_id Desired build id.
@ -89,8 +89,8 @@ module OneGadget
# When local not found, try search in latest version?
# @return [Array<Gadget::Gadget>?] Gadgets.
def builds(build_id, remote: true)
require_all if BUILDS.empty?
return BUILDS[build_id] if BUILDS.key?(build_id)
ret = find_build(build_id)
return ret unless ret.nil?
return build_not_found unless remote
# fetch remote builds
@ -145,10 +145,11 @@ module OneGadget
private
def require_all
Dir.glob(File.join(BUILDS_PATH, '**', '*.rb')).each do |dic|
def find_build(id)
Dir.glob(File.join(BUILDS_PATH, "*-#{id}.rb")).each do |dic|
require dic
end
BUILDS[id] if BUILDS.key?(id)
end
def build_not_found