trailblazer-loader 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 18a5ed1bc354d6f61c381c4526eedda3c29004e6
4
- data.tar.gz: 2f6983c10777f74d8a9db79a96408110a924f91b
3
+ metadata.gz: 3156c8edcfa6d906d4aa3c00451d7cf97ac64818
4
+ data.tar.gz: cf6e6648d5572126e3bf3c948b6b4171f8845e31
5
5
  SHA512:
6
- metadata.gz: fc7fd466bfe948e912e790c1b3a8e90816b35130a5150c78bd7f6808289bfa77e2333352f7256a98a698445adf9704868c3ce2415fdbef0548220197e306378d
7
- data.tar.gz: 0be790b9775f054e80c617002d23cf915d2247a322ac732d2e5fc1871dd409e08ef9d0be31ca64c8d6d84bcb7aaffccee53a313dc8a59cb77c6e4f03e1d24cd3
6
+ metadata.gz: 1d5059d6810255673f9a76d92ca9e34b1dae89b61c9a0372e788399475ce7ba46d6e99018f168a2b63392d1598694334ecc1d4c069380572b863b03e555d18c2
7
+ data.tar.gz: 34c735b25591d197789a438d771550a0eed3edf51e60c34b91480eb0524133a3df6ee86e5e6c6b3daf6f9cbb95881ff8eb100d1c68aa9dd00fafd3269add703a
data/CHANGES.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 0.0.2
2
+
3
+ * Internally, use `Representable::Pipeline` to model the loading steps. This allows gems like `trailblazer-rails` to plug in additional loading steps.
4
+
1
5
  # 0.0.1
2
6
 
3
7
  * Obviously, the first version ever. This implements the "lexical-width" strategy, only.
@@ -0,0 +1,22 @@
1
+
2
+ ```ruby
3
+ container = {
4
+ find_concepts: FindConcepts,
5
+ sort_concepts: SortConcepts,
6
+ set_name: ConceptName,
7
+ concept_files: ConceptFiles,
8
+ }
9
+
10
+ require "call_sheet"
11
+ sheet = CallSheet(container: container) do
12
+ map :find_concepts
13
+ map :sort_concepts
14
+ end
15
+
16
+ require "pp"
17
+ options[:files] = []
18
+ pp sheet.(options, all: [1])
19
+ ```
20
+
21
+ * how to include step at certain position? e.g. from trailblazer-rails
22
+ * pass options to all steps
@@ -1,41 +1,48 @@
1
1
  require "trailblazer/loader/version"
2
+ require "representable/pipeline"
2
3
 
3
4
  module Trailblazer
4
5
  class Loader
5
6
  # Please note that this is subject to change - we're still finding out the best way
6
7
  # to explicitly load files.
7
- def call(app_root)
8
- operations = Dir.glob("app/concepts/**/operation.rb").sort { |a, b| a.split("/").size <=> b.split("/").size }
9
- # lame heuristic, but works for me: sort by nested levels.
10
- # app/concepts/comment
11
- # app/concepts/api/v1/comment
12
-
13
-
14
-
15
- operations.each do |f|
16
- path = f.sub("app/concepts/", "")
17
- model = path.sub("/operation.rb", "")
18
-
19
- concept = model # comment, api/v1/comment, ...
20
-
21
- puts "digging through #{concept}"
8
+ #
9
+ # NOTE: i will most probably use call_sheet and dry-container here soon.
10
+ def call(options={}, &block)
11
+ options[:concepts_root] ||= "app/concepts/"
12
+
13
+ pipeline = options[:pipeline] || Representable::Pipeline[
14
+ FindConcepts,
15
+ SortConcepts,
16
+ Representable::Collect[ConceptName, ConceptFiles] # per concept.
17
+ ]
18
+
19
+ if args = options[:insert] # FIXME: this only implements a sub-set.
20
+ # pipeline = Representable::Pipeline::Insert.(pipeline, *args) # FIXME: implement :before in Pipeline.
21
+ pipeline[2].insert(pipeline[2].index(args.last[:before]), args.first)
22
+ end
22
23
 
23
- puts "@@@@@---> #{app_root}/app/models/#{model}" unless File.exist?("#{app_root}/app/models/#{model}.rb")
24
+ files = pipeline.([], options).flatten
24
25
 
25
- # app/models/ # FIXME: where's the namespace here?
26
- yield "#{app_root}/app/models/#{model}" if File.exist?("#{app_root}/app/models/#{model}.rb") # load the model file, first (thing.rb).
26
+ # require "pp"
27
+ # pp files
27
28
 
29
+ load_files(files, &block)
30
+ end
28
31
 
29
- [:contract, :representer, :callback, :cell, :policy].each do |asset|
30
- file = "#{app_root}/app/concepts/#{concept}/#{asset}"
31
- puts "loading extension... #{file.inspect}"
32
- yield file if File.exist?("#{file}.rb") # load the model file, first (thing.rb).
33
- end
32
+ FindConcepts = ->(input, options) { Dir.glob("#{options[:concepts_root]}**/") }
33
+ # lame heuristic, but works for me: sort by nested levels.
34
+ # app/concepts/comment
35
+ # app/concepts/api/v1/comment
36
+ SortConcepts = ->(input, options) { input.sort { |a, b| a.split("/").size <=> b.split("/").size } }
37
+ # Extract concept name from path, e.g. /api/v1/comment.
38
+ ConceptName = ->(input, options) { options[:name] = input.sub(options[:concepts_root], "").chomp("/"); [] }
39
+ # Find all .rb files in one particular concept directory, e.g. as in /concepts/comment/*.rb.
40
+ ConceptFiles = ->(input, options) { input += Dir.glob("#{options[:concepts_root]}#{options[:name]}/*.rb") }
34
41
 
42
+ private
35
43
 
36
- # concepts/:namespace/operation.rb
37
- yield "#{app_root}/#{f}" # load app/concepts/{concept}/crud.rb (Thing::Create, Thing::Update, and so on).
38
- end
44
+ def load_files(files)
45
+ files.each { |file| yield file }
39
46
  end
40
47
  end
41
48
  end
@@ -1,5 +1,5 @@
1
1
  module Trailblazer
2
2
  class Loader
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trailblazer-loader
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Sutterer
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-12-14 00:00:00.000000000 Z
11
+ date: 2015-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -65,6 +65,7 @@ files:
65
65
  - Gemfile
66
66
  - README.md
67
67
  - Rakefile
68
+ - call_sheet-notes.md
68
69
  - lib/trailblazer-loader.rb
69
70
  - lib/trailblazer/loader.rb
70
71
  - lib/trailblazer/loader/version.rb