Sha256: aae0c48c9740a05edc5d1c81d1270f38f8a156158eaac369209805c71e832c92

Contents?: true

Size: 1021 Bytes

Versions: 2

Compression:

Stored size: 1021 Bytes

Contents

module Trailblazer
  class Railtie < Rails::Railtie
    def self.autoload_crud_operations(app)
      Dir.glob("app/concepts/**/crud.rb") do |f|
        path  = f.sub("app/concepts/", "")
        model = path.sub("/crud.rb", "")

        require_dependency "#{app.root}/app/models/#{model}" # load the model file, first (thing.rb).
        require_dependency "#{app.root}/#{f}" # load app/concepts/{concept}/crud.rb (Thing::Create, Thing::Update, and so on).
      end
    end

    # thank you, http://stackoverflow.com/a/17573888/465070
    initializer 'trailblazer.install', after: :load_config_initializers do |app|
      # the trb autoloading has to be run after initializers have been loaded, so we can tweak inclusion of features in
      # initializers.
      if Rails.configuration.cache_classes
        Trailblazer::Railtie.autoload_crud_operations(app)
      else
        ActionDispatch::Reloader.to_prepare do
          Trailblazer::Railtie.autoload_crud_operations(app)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
trailblazer-0.2.2 lib/trailblazer/rails/railtie.rb
trailblazer-0.2.1 lib/trailblazer/rails/railtie.rb