trailblazer/trailblazer-loader

Not requiring model files

Hermanverschooten opened this issue · 5 comments

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 method customers' for #Class:0x007f9a623652a0`

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"]

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.

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.

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.

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

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