Giter VIP home page Giter VIP logo

chanko's Issues

Suggested way to test against Chanko 2.0?

Recently I started to play and adopt Chanko into our project. It works nicely and really changes the way we work.

However, I found that in Chanko 2.0, the unit generator no longer creates spec files for units, and since there's no need to run install generator in 2.0, the app/units folder is also not symlinked to /spec.

What is the suggested way to test against Chanko 2.0?

Rails 6.0 x zeitwerk の環境において units_directory_path が固定されてしまう場合がある

背景

cookpad_all では Rails 6.0 で zeitwerk を使っている状況で Chanko を使っています。
また Chanko::Config の設定については config/initializers 以下に Chanko 用のファイルを用意してそこで各種値を設定しており、そこで unit を置くディレクトリを Chanko::Config.units_directory_path = "app/extensions" で変更しています。

問題

上で設定した units_directory_path が反映されず、デフォルトである app/units で固定されてしまいます。

原因

Chanko::Config は一度 units_directory_path を読み出そうとしたタイミングで現在の @units_directory_path の値をキャッシュしています。

def units_directory_path
@resolved_units_directory_path ||= Rails.root.join(@units_directory_path).to_s
end

また、zeitwerk 環境下では以下のコードにより before: :set_autoload_paths のタイミングで Chanko::Loader.prepare_eager_load が呼び出されます。これは initializers 以下のコードが実行されるよりも前のタイミングです。

initializer("chanko.zeitwerk.prepare_eager_load", before: :set_autoload_paths) do |app|
# zeitwerk freezes autoload_paths after :set_autoload_paths.
# So we need to prepare before set_autoload_paths
Chanko::Loader.prepare_eager_load(mode: :zeitwerk)
end

この prepare_eager_load の中で Chanko::Config::units_directory_path が読み出されているんですが、その時点ではまだ units_directory_path がデフォルト値なのでそちらの値でパスが固定されます。

Rails.autoloaders.main.collapse(Chanko::Config.units_directory_path + '/*')

確認したいこと

  • この仕様は意図したしようでしょうか。
  • もし意図した挙動であれば少しハマりやすいポイントなので、以下のような対応をしたいです。
    • ドキュメントにパスの設定は initializers ではなく application.rb や environment などに書くことを記述する。
    • @resolved_units_directory_path に一度値が入ってしまった場合、 @units_directory_path にいくら値を入れても Chanko で利用するパスは変更できないので、units_directory_path=(path)@resolved_units_directory_path が nil でないときに例外を吐くなどをしたい。
  • もし意図していない挙動であればちょっと修正方針を考えたいです。

Rails6(開発環境)において、Viewファイル保存後のリロードで、Unit側のViewファイルの呼び出しが失敗する

発生環境

Rails6 + development + zeitwerk及びclassicのview拡張

再現方法

scope(:view) do
  function(:hello) do
    render '/hello'
  end
end

上記をviewファイルから呼び出した状態で、viewファイル「のみ」を保存しリロードすると、下記のエラーが発生する。

  [Chanko] ActionView::Template::Error - undefined method `_app_units_hello_world_views__hello_html_erb__3197552978688360732_19600' for #<ActionView::Base:0x00000000009ad8>

原因(調査中)

Rails6ではViewファイルを保存するたびにActionView::Baseを作り直すようで、Unitで事後に定義したviewファイルの追加設定が反映されない。

Rails6

1. Viewクラスのインスタンス(viewでのself.__id__)
	- リロード => 不変
	- Viewファイル書き換え => 変更
	- Modelファイル書き換え => 変更
2. Model/Unit
	- リロード => 不変
	- Viewファイル書き換え => 不変
	- Modelファイル書き換え => 変更

Rails5

1. Viewクラスのインスタンス(viewでのself.__id__)
	- リロード => 不変
	- Viewファイル書き換え => 不変
	- Modelファイル書き換え => 変更
3. Model/Unit
	- リロード => 不変
	- Viewファイル書き換え => 不変
	- Modelファイル書き換え => 変更

New features

Hi there

I might be missing something but am wondering what the best practice would be when prototyping a feature that requires "new" routes and controllers. The readme covers scenarios where the feature is implemented as an extension to existing controllers, models and views but I don't see a story for units that include new routes and controllers. I guess what I was expecting to see for this was some kind of :routes scope?

Is this something that you've considered and if so can you provide some guidance?

Thanks

Richie

Support for rail 3.2.x

Hi, this is not an issue, but a simple question whether it works with rails 3.2.x versions?

When using zeitwerk, eager_load fails in production mode

This can be avoided by letting zeitwerk do the work instead of using Chanko :: Loader.
So in my project I added the following code in config/application.rb

config.before_configuration do
  Chanko::Config.eager_load = false
end

Is it possible to add a decision process to determine if zeitwerk is used in the next part, like #57?
https://github.com/cookpad/chanko/blob/master/lib/chanko/railtie.rb#L24
https://github.com/cookpad/chanko/blob/master/lib/chanko/railtie.rb#L30

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.