Sha256: 07a41f825f6d1c607031d90bf87168c6502dd2df43acceff8b8256b9b11aa3f2

Contents?: true

Size: 748 Bytes

Versions: 4

Compression:

Stored size: 748 Bytes

Contents

require 'lhc'

module LHS
  class RequireLhsRecords
    def initialize(app)
      @app = app
    end

    def call(env)
      self.class.require_records
      @app.call(env)
    end

    def self.require_records
      Dir.glob(Rails.root.join('app/models/**/*.rb')).each do |file|
        require_dependency file if File.read(file).match('LHS::Record')
      end
    end
  end
end

Gem.find_files('lhs/**/*.rb').sort.each { |path| require path }

# Preload all the LHS::Records that are defined in app/models
class Engine < Rails::Engine
  initializer 'Load all LHS::Records from app/models/**' do |app|
    LHS::RequireLhsRecords.require_records
    next if app.config.cache_classes

    app.config.middleware.use LHS::RequireLhsRecords
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
lhs-10.1.1 lib/lhs.rb
lhs-10.1.0 lib/lhs.rb
lhs-10.0.0 lib/lhs.rb
lhs-9.1.1 lib/lhs.rb