Skip to content

Commit

Permalink
Merge 21e328d into e4cde2b
Browse files Browse the repository at this point in the history
  • Loading branch information
r7kamura committed May 26, 2014
2 parents e4cde2b + 21e328d commit 4855000
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/chanko/loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ def load(unit_name)
def cache
@cache ||= {}
end

def eager_load_units!
Pathname.glob("#{Rails.root}/#{Config.units_directory_path}/*").select(&:directory?).each do |path|
load(path.to_s.split("/").last.to_sym) rescue nil
end
end
end

def initialize(name)
Expand Down
6 changes: 6 additions & 0 deletions lib/chanko/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,11 @@ class Railtie < Rails::Railtie
::ActiveRecord::Associations::CollectionAssociation.send(:include, UnitProxyProvider)
end
end

if Rails.env.production?
initializer "chanko.prevent_units_directory_from_eager_loading" do |app|
config.eager_load_paths.delete(Rails.root.join(Chanko::Config.units_directory_path).to_s)
Chanko::Loader.eager_load_units!
end
end
end

0 comments on commit 4855000

Please sign in to comment.