trailblazer-loader 0.0.4 → 0.0.5

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: 8f993eca956a001ec251af5f8635dc5dd74ea5e0
4
- data.tar.gz: 26a5ae8a81b39c05ac8de3bb81629d11ec1a456e
3
+ metadata.gz: e8c0e3c79507f5a6a5f4f2383e062cb120cb6ace
4
+ data.tar.gz: d8712b8524753c3e8c0b96300f0cd9b25fbbedde
5
5
  SHA512:
6
- metadata.gz: 40b4ecbc9a013b6ba73094130b85d31221fdfd8aff7f657248aa69a40707c68626dac426da94c2ce531ff346592b1020864fc7e6204fbf550e993853dfde4338
7
- data.tar.gz: 7b53184a5e2558b3d116cb53fb70c2f5a9259e5e3cc42dcec6f898886fd17291c50f5d0d8178a309093f2c8a0127dcd16b87cd047eae55da6845fcad65e7be0f
6
+ metadata.gz: f103cc770a466b813f5142ec95b27a8f0665e7b74b041f178a5a0f0a40b613869114794638b1e1a4bf12cc2610dd5637884a42a819c591353286c9add8b7399a
7
+ data.tar.gz: f12a70084297229f4845f16d5dc637a3ab28b82c1feb9e0bdb3174cc59355d22d856f715a085f1517016ae719fe0a6d6567dbc5b1b55b596dfdb3acbdd01414e
data/CHANGES.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 0.0.5
2
+
3
+ * Remove `representable` dependency. This is a temporary fix until we have a pipelining gem.
4
+
1
5
  # 0.0.4
2
6
 
3
7
  * Fix loading for explicit layouts.
data/README.md CHANGED
@@ -115,7 +115,7 @@ app
115
115
  │   │   ├── contracts
116
116
  │   │   │ ├── create.rb
117
117
  │   │   │ └── update.rb
118
- │   │   ├── operation
118
+ │   │   ├── operations
119
119
  │   │   │ ├── create.rb
120
120
  │   │   │ └── update.rb
121
121
  │   │   ├── admin
@@ -233,6 +233,21 @@ module Comment::Operation
233
233
 
234
234
  ## Debugging
235
235
 
236
+ TODO: document PrintFiles
237
+
238
+ Booting your app fails because the loading order is incorrect? This happens, as we can't cover every possible combination.
239
+
240
+ In any case, you can use `require` or `require_relative` and load files manually in the file depending on a specific class.
241
+
242
+ For example, say you derive in another order and you're using the explicit layout.
243
+
244
+ ```ruby
245
+ require_relative "update.rb"
246
+ class Comment::Create < Comment::Update
247
+ ```
248
+
249
+ Instead of painfully reconfiguring, require explicitly and save yourself a lot of pain. BTW, that's how every other programming language does dependency management and even [Matz is not too happy about autoloading anymore](https://twitter.com/yukihiro_matz/status/676170870226706432).
250
+
236
251
  ## Customizing
237
252
 
238
253
  Trailblazer-loader allows you to inject your own sorting and filtering logic, should you refuse to go mainstream.
@@ -1,5 +1,4 @@
1
1
  require "trailblazer/loader/version"
2
- require "representable/pipeline"
3
2
  require "pp"
4
3
 
5
4
  module Trailblazer
@@ -12,12 +11,12 @@ module Trailblazer
12
11
  options[:concepts_root] ||= "app/concepts/"
13
12
  options[:concept_dirs] = concept_dirs
14
13
 
15
- pipeline = options[:pipeline] || Representable::Pipeline[
14
+ pipeline = options[:pipeline] || Pipeline[
16
15
  FindDirectories,
17
16
  FindConcepts,
18
17
  # PrintConcepts,
19
18
  SortByLevel,
20
- Representable::Collect[ConceptName, ConceptFiles, SortCreateFirst, SortOperationLast, AddConceptFiles] # per concept.
19
+ Pipeline::Collect[ConceptName, ConceptFiles, SortCreateFirst, SortOperationLast, AddConceptFiles] # per concept.
21
20
  ]
22
21
 
23
22
  if args = options[:insert] # FIXME: this only implements a sub-set.
@@ -67,3 +66,5 @@ module Trailblazer
67
66
  end
68
67
  end
69
68
  end
69
+
70
+ require "trailblazer/loader/pipeline"
@@ -0,0 +1,78 @@
1
+ module Trailblazer
2
+ # WARNING: this will be removed soon with Uber::Pipeline or CallSheet.
3
+ class Loader::Pipeline < Array
4
+ Stop = Class.new
5
+
6
+ # options is mutuable.
7
+ def call(input, options)
8
+ inject(input) do |memo, block|
9
+ res = evaluate(block, memo, options)
10
+ return(Stop)if Stop == res
11
+ res
12
+ end
13
+ end
14
+
15
+ private
16
+ def evaluate(block, input, options)
17
+ block.call(input, options)
18
+ end
19
+
20
+
21
+ module Macros # TODO: explicit test.
22
+ # Macro to quickly modify an array of functions via Pipeline::Insert and return a
23
+ # Pipeline instance.
24
+ def insert(functions, new_function, options)
25
+ Pipeline.new(Pipeline::Insert.(functions, new_function, options))
26
+ end
27
+ end
28
+ extend Macros
29
+
30
+ # Collect applies a pipeline to each element of input.
31
+ class Collect < self
32
+ # when stop, the element is skipped. (should that be Skip then?)
33
+ def call(input, options)
34
+ arr = []
35
+ input.each_with_index do |item_fragment, i|
36
+ result = super(item_fragment, options.merge(index: i)) # DISCUSS: NO :fragment set.
37
+ Stop == result ? next : arr << result
38
+ end
39
+ arr
40
+ end
41
+ end # Collect
42
+
43
+ module Function
44
+ class Insert
45
+ def call(arr, func, options)
46
+ arr = arr.dup
47
+ delete!(arr, func) if options[:delete]
48
+ replace!(arr, options[:replace], func) if options[:replace]
49
+ arr
50
+ end
51
+
52
+ private
53
+ def replace!(arr, old_func, new_func)
54
+ arr.each_with_index { |func, index|
55
+ if func.is_a?(Collect)
56
+ arr[index] = Collect[*Pipeline::Insert.(func, new_func, replace: old_func)]
57
+ end
58
+
59
+ arr[index] = new_func if func==old_func
60
+ }
61
+ end
62
+
63
+ def delete!(arr, removed_func)
64
+ arr.delete(removed_func)
65
+
66
+ # TODO: make nice.
67
+ arr.each_with_index { |func, index|
68
+ if func.is_a?(Collect)
69
+ arr[index] = Collect[*Pipeline::Insert.(func, removed_func, delete: true)]
70
+ end
71
+ }
72
+ end
73
+ end
74
+ end
75
+
76
+ Insert = Function::Insert.new
77
+ end
78
+ end
@@ -1,5 +1,5 @@
1
1
  module Trailblazer
2
2
  class Loader
3
- VERSION = "0.0.4"
3
+ VERSION = "0.0.5"
4
4
  end
5
5
  end
@@ -21,6 +21,4 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency "bundler", "~> 1.10"
22
22
  spec.add_development_dependency "rake", "~> 10.0"
23
23
  spec.add_development_dependency "minitest"
24
-
25
- spec.add_dependency "representable", ">= 2.4.0" # NOTE: this is only until we agree on how to model pipelines (as in call_sheet, Pipeline, etc).
26
24
  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.4
4
+ version: 0.0.5
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-17 00:00:00.000000000 Z
11
+ date: 2015-12-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,20 +52,6 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: representable
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: 2.4.0
62
- type: :runtime
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: 2.4.0
69
55
  description: 'TOD: Write a longer description or delete this line.'
70
56
  email:
71
57
  - apotonick@gmail.com
@@ -82,6 +68,7 @@ files:
82
68
  - call_sheet-notes.md
83
69
  - lib/trailblazer-loader.rb
84
70
  - lib/trailblazer/loader.rb
71
+ - lib/trailblazer/loader/pipeline.rb
85
72
  - lib/trailblazer/loader/version.rb
86
73
  - trailblazer-loader.gemspec
87
74
  homepage: http://trailblazer.to/