trailblazer-loader 0.0.9 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 834b1fea8e8901fdabf13ec60bc9fe18096219a1
4
- data.tar.gz: 3678824bf53a228bea541e24d592a74a384810a6
3
+ metadata.gz: f975435027b00685780102cadeb527eec303f687
4
+ data.tar.gz: d9b1808f03432b5cf0536d20aed9eb3ddc5be540
5
5
  SHA512:
6
- metadata.gz: e0075624d8d4eee0c286edab53eab61fd69c612ccabeea6bcde1ce619334edd562a15ba3905631db75717d1c40cc807fac471e1529d6cb63c7281b19762e1fda
7
- data.tar.gz: 6e6231501f23b037e87460be30438f29edead8d4120b8f9ba2f6cce89d2e3a9c3a6140bcf5ca87ac635c04e3a144c471aeb84dc234d57b45fc8de9389f3909c2
6
+ metadata.gz: cee8af018a6c130d725394e0cf3c52c9813c5afeb45b572c58546d4bb9d2ee20287af170dede5597065416deed6ce93fd09b7a4e5cfe6ade93bcf3c6bf12a32e
7
+ data.tar.gz: b1aab9bc12f494e23c311b8e2364b979091519630e63ce337bc547c0fcb6ed8de6f3e427563017e9795b44a4ae062741ef9c091f7b310141ed390e39e9a9f45f
data/CHANGES.md CHANGED
@@ -1,3 +1,12 @@
1
+ # 0.1.0
2
+
3
+ * New option `:root` to allow using loader for sources other than the current directory, e.g. for gems or Rails engines.
4
+ * `:concept_root` is now prefixed with `:root`.
5
+ * Use `File::SEPARATOR` for filename operations.
6
+ * Don't use a regexp anymore to find concept files, but `Loader#concept_dirs` which includes plural names.
7
+ * Allow irregular directory names such as `policies`.
8
+ * Allow prepending to the pipeline using `:prepend`. Note that this is a temporary API and will be removed.
9
+
1
10
  # 0.0.9
2
11
 
3
12
  * Bug fix :cough:.
data/README.md CHANGED
@@ -193,7 +193,13 @@ You do not need this step should you use one of the following binding gems.
193
193
  Trailblazer::Loader.new.() { |file| require_dependency(File.join(Rails.app.root, file)) }
194
194
  ```
195
195
 
196
- `:concepts_root`
196
+ Per default, Trailblazer-loader will use `app/concepts` as the root path for the file search. Change that with the `:concepts_root` option.
197
+
198
+ ```ruby
199
+ Trailblazer::Loader.new.(concepts_root: "./concepts/") { |file| require_relative(file) }
200
+ ```
201
+
202
+ Note that `:concepts_root` needs a trailing slash.
197
203
 
198
204
  ## Mixing
199
205
 
@@ -3,13 +3,18 @@ require "pp"
3
3
 
4
4
  module Trailblazer
5
5
  class Loader
6
+
7
+ def concept_dirs
8
+ %w{ callback cell contract operation policy representer view
9
+ callbacks cells contracts operations policies representers views }
10
+ end
11
+
6
12
  # Please note that this is subject to change - we're still finding out the best way
7
13
  # to explicitly load files.
8
- #
9
- # NOTE: i will most probably use call_sheet and dry-container here soon.
10
14
  def call(options={}, &block)
11
- options[:concepts_root] ||= "app/concepts/"
12
- options[:concept_dirs] = concept_dirs
15
+ options[:root] ||= "."
16
+ options[:concepts_root] ||= "#{options[:root]}/app/concepts/"
17
+ options[:concept_dirs] ||= concept_dirs
13
18
 
14
19
  pipeline = options[:pipeline] || Pipeline[
15
20
  FindDirectories,
@@ -22,6 +27,9 @@ module Trailblazer
22
27
  # pipeline = Representable::Pipeline::Insert.(pipeline, *args) # FIXME: implement :before in Pipeline.
23
28
  pipeline.last.insert(pipeline.last.index(args.last[:before]), args.first)
24
29
  end
30
+ if args = options[:prepend]
31
+ pipeline << args
32
+ end
25
33
 
26
34
  files = pipeline.([], options).flatten
27
35
 
@@ -34,19 +42,15 @@ module Trailblazer
34
42
  pp files if options[:debug]
35
43
  end
36
44
 
37
- def concept_dirs
38
- %w{ callback cell contract operation policy representer view }
39
- end
40
-
41
45
  FindDirectories = ->(input, options) { Dir.glob("#{options[:concepts_root]}**/") }
42
46
  # Filter out all directories containing /(callback|cell|contract|operation|policy|representer|view)/
43
- FindConcepts = ->(input, options) { input.shift; input.reject { |dir| dir =~ /(#{options[:concept_dirs].join("|")})/ } }
47
+ FindConcepts = ->(input, options) { input.reject { |dir| (dir.split(File::SEPARATOR) & options[:concept_dirs]).any? } }
44
48
  PrintConcepts = ->(input, options) { puts " concepts: #{input.inspect}"; input }
45
49
 
46
50
  # lame heuristic, but works for me: sort by directory levels.
47
51
  # app/concepts/comment
48
52
  # app/concepts/api/v1/comment
49
- SortByLevel = ->(input, options) { input.sort { |a, b| a.split("/").size <=> b.split("/").size } }
53
+ SortByLevel = ->(input, options) { input.sort { |a, b| a.split(File::SEPARATOR).size <=> b.split(File::SEPARATOR).size } }
50
54
  # Extract concept name from path, e.g. /api/v1/comment.
51
55
  ConceptName = ->(input, options) { options[:name] = input.sub(options[:concepts_root], "").chomp("/"); [] }
52
56
  # Find all .rb files in one particular concept directory, e.g. as in /concepts/comment/*.rb.
@@ -55,7 +59,7 @@ module Trailblazer
55
59
 
56
60
  Dir.glob("#{options[:concepts_root]}#{options[:name]}/*.rb") + # .rb files directly in this concept.
57
61
  Dir.glob("#{options[:concepts_root]}#{options[:name]}/*/*.rb"). # .rb in :concept/operation/*.rb
58
- find_all { |file| file =~ /(#{options[:concept_dirs].join("|")})/ } # but only those, no sub-concepts!
62
+ find_all { |file| (file.split(File::SEPARATOR) & options[:concept_dirs]).any? } # but only those, no sub-concepts!
59
63
  end
60
64
 
61
65
  # operation files should be loaded after callbacks, policies, and the like: [callback.rb, contract.rb, policy.rb, operation.rb]
@@ -63,6 +67,8 @@ module Trailblazer
63
67
  SortCreateFirst = ->(input, options) { input.sort }
64
68
  AddConceptFiles = ->(input, options) { input }
65
69
 
70
+
71
+ # FindRbFiles = ->(input, options) { input + Dir.glob("#{options[:concepts_root]}#{options[:name]}/*.rb") }
66
72
  private
67
73
 
68
74
  def load_files(files)
@@ -1,5 +1,5 @@
1
1
  module Trailblazer
2
2
  class Loader
3
- VERSION = "0.0.9"
3
+ VERSION = "0.1.0"
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.9
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Sutterer
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-01-22 00:00:00.000000000 Z
11
+ date: 2016-08-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler