lib/trailblazer/loader.rb in trailblazer-loader-0.0.5 vs lib/trailblazer/loader.rb in trailblazer-loader-0.0.6
- old
+ new
@@ -46,19 +46,20 @@
SortByLevel = ->(input, options) { input.sort { |a, b| a.split("/").size <=> b.split("/").size } }
# Extract concept name from path, e.g. /api/v1/comment.
ConceptName = ->(input, options) { options[:name] = input.sub(options[:concepts_root], "").chomp("/"); [] }
# Find all .rb files in one particular concept directory, e.g. as in /concepts/comment/*.rb.
ConceptFiles = ->(input, options) do
+ input + # allow injecting other dependencies, e.g. app/models/comment.rb.
+
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
# operation files should be loaded after callbacks, policies, and the like: [callback.rb, contract.rb, policy.rb, operation.rb]
SortOperationLast = ->(input, options) { input.sort { |a, b| (a =~ /operation/ && b !~ /operation/) ? 1 : -1 } }
SortCreateFirst = ->(input, options) { input.sort }
AddConceptFiles = ->(input, options) { input }
-
private
def load_files(files)
files.each { |file| yield file }