pocke / rbs_rails

Apache License 2.0
285 stars 33 forks source link

Improve scope declaration #197

Closed ksss closed 3 years ago

ksss commented 3 years ago

This PR supports more scope declarations.

  1. defined in ActiveSupport::Concern#included
  2. enum not_*

How to implement

Monkey patch ActiveRecord::Scoping::Named::ClassMethods#scope to collect the real definition information for each model class. Use Proc#parameters to determine the arguments.

ksss commented 3 years ago

I don't know why fail CI on head.

rake aborted!
NoMethodError: undefined method `each' for false:FalseClass

        options.rakelib.each do |rlib|
                       ^^^^^
/Users/ksss/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/rake-13.0.3/lib/rake/application.rb:705:in `raw_load_rakefile'
/Users/ksss/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/rake-13.0.3/lib/rake/application.rb:104:in `block in load_rakefile'
/Users/ksss/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/rake-13.0.3/lib/rake/application.rb:186:in `standard_exception_handling'
/Users/ksss/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/rake-13.0.3/lib/rake/application.rb:103:in `load_rakefile'
/Users/ksss/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/rake-13.0.3/lib/rake/application.rb:82:in `block in run'
/Users/ksss/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/rake-13.0.3/lib/rake/application.rb:186:in `standard_exception_handling'
/Users/ksss/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/rake-13.0.3/lib/rake/application.rb:80:in `run'
bin/rake:4:in `<main>'

Maybe openstruct is broken?

irb(#<Rake::Application:0x0000000108a5cec8>):001:0> options
=> #<OpenStruct always_multitask=false, backtrace=false, build_all=false, dryrun=false, ignore_deprecate=false, ignore_system=false, job_stats=false, load_system=false, nosearch=false, rakelib=["rakelib"], show_all_tasks=false, show_prereqs=false, show_task_pattern=nil, show_tasks=nil, silent=false, suppress_backtrace_pattern=nil, thread_pool_size=12, trace=false, trace_output=#<IO:<STDERR>>, trace_rules=false, false=false>
# what is `false=false` ?
irb(#<Rake::Application:0x0000000108a5cec8>):002:0> options.rakelib
=> false
# inspect show `rakelib=["rakelib"]` why return `false` ?
pocke commented 3 years ago

Thanks for your pull request!

Monkey patch ActiveRecord::Scoping::Named::ClassMethods#scope to collect the real definition information for each model class.

I'm planning to replace the other generation methods with a similar way. Such as enum. ref: https://github.com/pocke/rbs_rails/issues/6 So I'll re-design the whole the structure. Please give me some time :pray:

ksss commented 3 years ago

OK, Cool! I'm looking forward to that ✨ I'll close this PR.