class Trailblazer::Loader

Constants

AddConceptFiles
ConceptFiles

Find all .rb files in one particular concept directory, e.g. as in /concepts/comment/*.rb.

ConceptName

Extract concept name from path, e.g. /api/v1/comment.

FindConcepts

Filter out all directories containing /(callback|cell|contract|operation|policy|representer|view)/

FindDirectories
PrintConcepts
SortByLevel

lame heuristic, but works for me: sort by directory levels. app/concepts/comment app/concepts/api/v1/comment

SortCreateFirst
SortOperationLast

operation files should be loaded after callbacks, policies, and the like: [callback.rb, contract.rb, policy.rb, operation.rb]

VERSION

Public Instance Methods

call(options={}, &block) click to toggle source

Please note that this is subject to change - we're still finding out the best way to explicitly load files.

# File lib/trailblazer/loader.rb, line 14
def call(options={}, &block)
  options[:root]          ||= "."
  options[:concepts_root] ||= "#{options[:root]}/app/concepts/"
  options[:concept_dirs]  ||= concept_dirs

  pipeline = options[:pipeline] || default_circuit

  if args = options[:insert] # FIXME: this only implements a sub-set.
    # pipeline = Representable::Pipeline::Insert.(pipeline, *args) # FIXME: implement :before in Pipeline.
    pipeline.last.insert(pipeline.last.index(args.last[:before]), args.first)
  end
  if args = options[:prepend]
    pipeline << args
  end

  files =  pipeline.([], options).flatten

  debug(files, options)

  load_files(files, &block)
end
concept_dirs() click to toggle source
# File lib/trailblazer/loader.rb, line 7
def concept_dirs
  %w{ callback  cell  contract  operation  policy   representer  view
      callbacks cells contracts operations policies representers views }
end
debug(files, options) click to toggle source
# File lib/trailblazer/loader.rb, line 45
def debug(files, options)
  pp files if options[:debug]
end
default_circuit() click to toggle source
# File lib/trailblazer/loader.rb, line 36
def default_circuit
  Pipeline[
    FindDirectories,
    FindConcepts,
    SortByLevel,
    Pipeline::Collect[ConceptName, ConceptFiles, SortCreateFirst, SortOperationLast, AddConceptFiles] # per concept.
  ]
end

Private Instance Methods

load_files(files) { |file| ... } click to toggle source

FindRbFiles = ->(input, options) { input + Dir.glob(“#{options}#{options}/*.rb”) }

# File lib/trailblazer/loader.rb, line 78
def load_files(files)
  files.each { |file| yield file }
end