Sha256: 7245171016fc28ee67bdc6352d530623dbe2f5f34084a98aaa6ee569e1005fc1

Contents?: true

Size: 1.69 KB

Versions: 2

Compression:

Stored size: 1.69 KB

Contents

# frozen_string_literal: true

after_bundle do
  generate :controller, 'test', 'index'
end

gem 'sassc-rails'
route "root to: 'test#index'"

environment <<~RUBY, env: :development
  # === GEM AUTO-RELOADING ===

  if defined?(::AMBER_EXTENSION_GEM)
    # create the file watcher paths hash for the extension gem
    reload_paths = {}
    dir = ::AMBER_EXTENSION_GEM.path.to_s
    reload_paths[dir] = ['rb']

    # define a file watcher for the extension gem
    extension_gem_reloader = config.file_watcher.new([], reload_paths) do
      puts '    Reloading the extension gem'

      # delete all constants defined by the extension gem
      ::AMBER_EXTENSION_GEM.constants.each do |const|
        # Normalize ::Foo, ::Object::Foo, Object::Foo, Object::Object::Foo, etc. as Foo.
        normalized = const.to_s.delete_prefix('::')
        normalized.sub!(/\A(Object::)+/, '')

        constants = normalized.split('::')
        to_remove = constants.pop
        parent = constants.empty? ? ::Object : ::Object.const_get(constants.join('::'))

        parent.__send__(:remove_const, to_remove)
      end

      # remove extension gems' files from the global
      # list of already required files
      $LOADED_FEATURES.reject! { _1.start_with?(::AMBER_EXTENSION_GEM.path) }

      # require this gem once again
      require ::AMBER_EXTENSION_GEM.require_path
    end

    ::Rails.application.reloaders << extension_gem_reloader

    first_reload = true
    config.to_prepare do
      puts '    Reloading app code'

      if first_reload
        first_reload = false
        next extension_gem_reloader.execute
      end

      extension_gem_reloader.execute_if_updated
    end
  end

  # === END GEM AUTO-RELOADING ===

RUBY

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
amber_extension_generator-1.0.0 lib/dummy_rails_app_template.rb
amber_extension_generator-0.0.5 lib/dummy_rails_app_template.rb