trailblazer / trailblazer-loader

Require concept files, models and more without any autoloading magic.
MIT License
17 stars 23 forks source link

Not requiring model files #3

Closed Hermanverschooten closed 8 years ago

Hermanverschooten commented 8 years ago

I do not know if this should be filed against trailblazer-loader / trailblazer-rails.

The list of files seems to return only the result of the ConceptFiles, and not of a previously injected step. Using the current version (0.0.5) and starting rails console outputs:

["app/concepts/address/cell.rb",
 "app/concepts/address/policies.rb",
 "app/concepts/address/operation/destroy.rb",
 "app/concepts/address/operation/create.rb",
 "app/concepts/address/operation/update.rb",
 "app/concepts/address/operation/show.rb",
 "app/concepts/address/operation/index.rb"]

The model class:

class Address < ActiveRecord::Base
  scope :customers, -> { where(customer: true) }
end

When I try Address.customers, it returns NoMethodError: undefined methodcustomers' for #`

If I check the input parameter for ConceptFiles, it does contain the list returned by the injected function (from trailblazer-rails), but they are not in the result.

I tried concatenating the input to the result and that works, but I know this is probably not what is needed. But it does add them.

ConceptFiles  = ->(input, options) do
  input + Dir.glob("#{options[:concepts_root]}#{options[:name]}/*.rb") +        # .rb files directly in this concept.
    Dir.glob("#{options[:concepts_root]}#{options[:name]}/*/*.rb").     # .rb in :concept/operation/*.rb
      find_all { |file| file =~ /(#{options[:concept_dirs].join("|")})/ } # but only those, no sub-concepts!
end

["app/concepts/address/cell.rb",
 "app/concepts/address/policies.rb",
 "app/models/address.rb",
 "app/concepts/address/operation/index.rb",
 "app/concepts/address/operation/destroy.rb",
 "app/concepts/address/operation/create.rb",
 "app/concepts/address/operation/update.rb",
 "app/concepts/address/operation/show.rb"]
apotonick commented 8 years ago

Oh, I started a discussion on the wrong issue.

The loader should be framework-agnostic, models should be in concepts/comment/model.rb and will be loaded automatically with the current implementation.

apotonick commented 8 years ago

Or, actually, wait, hm... Trying to work out if it would make sense to decouple persistence from concepts, because often a concept does not necessarily map to a database table(s), and we could keep the app/models directory, then.

Hermanverschooten commented 8 years ago

I'd prefer to keep my models in app/models, to cleanly separate the business logic from the persistence layer. If I understand the pipeline correctly it takes an input, performs some action on it and hands it to the next in the chain. But if you look at the ConceptFiles, it ignores the input, effectively forgetting the output from the inserted FindModels.

apotonick commented 8 years ago

I agree on separate directories, I also find `app/controllers quite ok.

Checked on gemgem-trbrb and I get the same problem!

Hermanverschooten commented 8 years ago

:+1: