pocke / rbs_rails

Apache License 2.0
280 stars 31 forks source link

Improve Rails.env type #31

Open pocke opened 4 years ago

pocke commented 4 years ago

ref: https://github.com/pocke/rbs_rails/pull/30

Currently, Rails.env type is just ActiveSupport::StringInquirer, but it actually has development? method and so on.

Now user can define an overload to define these methods.

class Rails
  overload def self.env: () -> (ActiveSupport::StringInquirer & _Envs)
end

interface _Envs
  def development?: () -> bool
  # ...
end

But, probably it should be rbs_rails responsibility.

And maybe it can generate custom environments, such as staging?.

grncdr commented 3 years ago

I think the best compromise is for rbs_rails to generate an overload with development/test/production methods. That way the common case is covered, but the overload can easily be edited to better suit the project.

BatuhanW commented 3 years ago

What about during the generation of types, parsing file names in config/environments folder and populating this interface with these values?