Skip to content

Commit

Permalink
Ensure to load project code with an order that is consistent across o…
Browse files Browse the repository at this point in the history
…perating systems
  • Loading branch information
jodosha committed Oct 22, 2016
1 parent 94887a6 commit 68343c8
Show file tree
Hide file tree
Showing 12 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ unless ENV['TRAVIS']
end

gem 'i18n'
gem 'hanami-utils', '~> 0.8', require: false, github: 'hanami/utils', branch: '0.8.x'
gem 'hanami-utils', '~> 0.8', require: false, github: 'hanami/utils', branch: 'master'
gem 'hanami-validations', '~> 0.6', require: false, github: 'hanami/validations', branch: 'master'
gem 'hanami-router', '~> 0.7', require: false, github: 'hanami/router', branch: 'master'
gem 'hanami-controller', '~> 0.7', require: false, github: 'hanami/controller', branch: '0.7.x'
Expand Down
2 changes: 1 addition & 1 deletion lib/hanami/application_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def force_ssl(value = nil)
#
# @since 0.1.0
#
# @see http://www.ruby-doc.org/core-2.1.2/Dir.html#method-c-pwd
# @see http://www.ruby-doc.org/core/Dir.html#method-c-pwd
#
# @example Getting the value
# require 'hanami'
Expand Down
4 changes: 3 additions & 1 deletion lib/hanami/assets/asset.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'hanami/utils/file_list'

module Hanami
module Assets
# Requested asset
Expand Down Expand Up @@ -60,7 +62,7 @@ def exist?
# @since 0.8.0
# @api private
def find_asset
Dir[PUBLIC_DIRECTORY].find do |asset|
Utils::FileList[PUBLIC_DIRECTORY].find do |asset|
yield asset unless ::File.directory?(asset)
end
end
Expand Down
3 changes: 2 additions & 1 deletion lib/hanami/commands/generate/migration.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'hanami/commands/generate/abstract'
require 'hanami/utils/file_list'

module Hanami
module Commands
Expand Down Expand Up @@ -42,7 +43,7 @@ def destination_path
end

def existing_migration_path
Dir.glob("#{Hanami::Model.configuration.migrations}/[0-9]*_#{underscored_name}.rb").first
Utils::FileList["#{Hanami::Model.configuration.migrations}/[0-9]*_#{underscored_name}.rb"].first
end

def new_migration_path
Expand Down
6 changes: 2 additions & 4 deletions lib/hanami/config/load_paths.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'hanami/utils/load_paths'
require 'hanami/utils'

module Hanami
module Config
Expand All @@ -7,16 +7,14 @@ module Config
# @since 0.1.0
# @api private
class LoadPaths < Utils::LoadPaths
PATTERN = '**/*.rb'.freeze

def initialize(root)
super()
@root = root
end

def load!
each do |path|
Dir.glob(path.join(PATTERN)).each { |file| require file }
Utils.require!(path)
end
end

Expand Down
1 change: 1 addition & 0 deletions lib/hanami/frameworks.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'hanami/utils'
require 'hanami/validations'
require 'hanami/router'
require 'hanami/view'
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Dir["#{__dir__}/<%= config[:project_name] %>/**/*.rb"].each { |file| require_relative file }
Hanami::Utils.require!("#{__dir__}/<%= config[:project_name] %>")
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ ENV['HANAMI_ENV'] ||= 'test'

require_relative '../config/environment'
Hanami.boot

Dir[__dir__ + '/support/**/*.rb'].each { |f| require f }
Hanami::Utils.require!("#{__dir__}/support")

# This file was generated by the `rspec --init` command. Conventionally, all
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
Expand Down
2 changes: 1 addition & 1 deletion lib/hanami/static.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def initialize(app, root: Hanami.public_directory, header_rules: HEADER_RULES)
def _urls(root)
return [] unless root.exist?

Dir.entries(root).map do |entry|
Dir.entries(root).sort.map do |entry|
next if EXCLUDED_ENTRIES.include?(entry)
"#{URL_PREFIX}#{entry}"
end.compact
Expand Down
3 changes: 1 addition & 2 deletions spec/integration/cli/new/test_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ class MiniTest::Spec
require_relative '../config/environment'
Hanami.boot
Dir[__dir__ + '/support/**/*.rb'].each { |f| require f }
Hanami::Utils.require!("\#{__dir__}/support")
# This file was generated by the `rspec --init` command. Conventionally, all
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
Expand Down
2 changes: 1 addition & 1 deletion spec/integration/cli/new_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@
# lib/<project>.rb
#
expect("lib/#{project}.rb").to have_file_content <<-END
Dir["\#{__dir__}/#{project}/**/*.rb"].each { |file| require_relative file }
Hanami::Utils.require!("\#{__dir__}/#{project}")
END

#
Expand Down
2 changes: 1 addition & 1 deletion spec/support/shared_examples/cli/new.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
# lib/<project>.rb
#
expect("lib/#{project}.rb").to have_file_content <<-END
Dir["\#{__dir__}/#{project}/**/*.rb"].each { |file| require_relative file }
Hanami::Utils.require!("\#{__dir__}/#{project}")
END

#
Expand Down

0 comments on commit 68343c8

Please sign in to comment.