trailblazer 0.3.2 → 0.3.3

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: 6fe908e23b8ef76962d2eba061d666567e204120
4
- data.tar.gz: 3df42356be844b922d258de9f3e64ed72f5b5a9c
3
+ metadata.gz: c6355544b09375074e8ef41304a2ccdf99d5bdf9
4
+ data.tar.gz: 5c80ec4a93e1628e84aa6a83290027ccfdb02cca
5
5
  SHA512:
6
- metadata.gz: 9190472c21be262f4a216f52180c9b91bbf9c073650148fe53aec8b83ba2493f0365d4d10ebd603daa4a9f6c295411a634f66b302e7d5895c6fe8fdca66783b4
7
- data.tar.gz: 119fbafbce0d79e95c9f4131400ba6860e12fe40f8e9e0901c4457da3450c0940915d9bb51e3ac0f502fd00cd6022224e4d082041dec843bf878537cdb3b6e71
6
+ metadata.gz: 6c27cbe26a73a84c413341a2d9ec528c80083d98b4110b71f8569a72961a3932790347c47389a7fda74d3aa61a5c196e8178fa186c86fa1016048726e71705eb
7
+ data.tar.gz: 4c359e9e33ea39d269710a04d615a59a4d8e53225f9438e2f70b3f83eb6182c85beea60479b54b34d6a193216ba61b86b12719e9f88df51bc5fd13b11364be29
data/CHANGES.md CHANGED
@@ -1,3 +1,8 @@
1
+ # 0.3.3
2
+
3
+ * Add `Operation::reject` which will run the block when _invalid_.
4
+ * In the railtie, require `trailblazer/autoloading` as I am assuming Rails users want maximum comfort.
5
+
1
6
  # 0.3.2
2
7
 
3
8
  * Allow to use `#contract` before `#validate`. The contract will be instantiated once per `#run` using `#contract` and then memoized. This allows to add/modify the contract _before_ you validate it using `#validate`.
data/README.md CHANGED
@@ -623,6 +623,19 @@ require "trailblazer/rails/railtie"
623
623
  This will go through `app/concepts/`, find all the `crud.rb` files, autoload their corresponding namespace (e.g. `Thing`, which is a model) and then load the `crud.rb` file.
624
624
 
625
625
 
626
+ ## Installation
627
+
628
+ The obvious needs to be in your `Gemfile`.
629
+
630
+ ```ruby
631
+ gem "trailblazer"
632
+ gem "cells"
633
+ ```
634
+
635
+ Cells is _not_ required per default! Add it if you use it, which is highly recommended.
636
+
637
+ A few quirks are required at the moment as Rails autoloading is giving us a hard time. The setup of an app [is documented here](https://github.com/apotonick/gemgem-trbrb/wiki/Things-You-Should-Know).
638
+
626
639
  ## Undocumented Features
627
640
 
628
641
  (Please don't read this section!)
@@ -26,6 +26,13 @@ module Trailblazer
26
26
  [res, op]
27
27
  end
28
28
 
29
+ # Like ::run, but yield block when invalid.
30
+ def reject(*args)
31
+ res, op = run(*args)
32
+ yield op if res == false
33
+ return op
34
+ end
35
+
29
36
  # ::call only returns the Operation instance (or whatever was returned from #validate).
30
37
  # This is useful in tests or in irb, e.g. when using Op as a factory and you already know it's valid.
31
38
  def call(*params)
@@ -16,6 +16,11 @@ module Trailblazer
16
16
  end
17
17
  end
18
18
 
19
+ # This is to autoload Operation::Dispatch, etc. I'm simply assuming people find this helpful in Rails.
20
+ initializer "trailblazer.library_autoloading" do
21
+ require "trailblazer/autoloading"
22
+ end
23
+
19
24
  # thank you, http://stackoverflow.com/a/17573888/465070
20
25
  initializer 'trailblazer.install', after: :load_config_initializers do |app|
21
26
  # the trb autoloading has to be run after initializers have been loaded, so we can tweak inclusion of features in
@@ -1,3 +1,3 @@
1
1
  module Trailblazer
2
- VERSION = "0.3.2"
2
+ VERSION = "0.3.3"
3
3
  end
@@ -0,0 +1,34 @@
1
+ require "test_helper"
2
+
3
+ class OperationRejectTest < MiniTest::Spec
4
+ class Operation < Trailblazer::Operation
5
+ def process(params)
6
+ invalid! if params == false
7
+ end
8
+ end
9
+
10
+ it do
11
+ run = nil
12
+ Operation.run(true) { run = true }
13
+ run.must_equal true
14
+ end
15
+
16
+ it do
17
+ run = nil
18
+ Operation.run(false) { run = true }
19
+ run.must_equal nil
20
+ end
21
+
22
+ it do
23
+ run = nil
24
+ op = Operation.reject(true) { run = true }
25
+ run.must_equal nil
26
+ op.must_be_instance_of Operation
27
+ end
28
+
29
+ it do
30
+ run = nil
31
+ Operation.reject(false) { run = true }
32
+ run.must_equal true
33
+ end
34
+ end
@@ -74,9 +74,17 @@ class Band < ActiveRecord::Base
74
74
  end
75
75
  end
76
76
 
77
- builds -> (params) do
78
- return JSON if params[:format] == "json"
79
- return Admin if params[:admin]
77
+ # TODO: wait for uber 0.0.10 and @dutow.
78
+ # builds -> (params) do
79
+ # return JSON if params[:format] == "json"
80
+ # return Admin if params[:admin]
81
+ # end
82
+ builds do |params|
83
+ if params[:format] == "json"
84
+ JSON
85
+ elsif params[:admin]
86
+ Admin
87
+ end
80
88
  end
81
89
  end
82
90
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trailblazer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Sutterer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-10 00:00:00.000000000 Z
11
+ date: 2015-07-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: uber
@@ -222,6 +222,7 @@ files:
222
222
  - test/fixtures/cells.png
223
223
  - test/module_test.rb
224
224
  - test/operation/contract_test.rb
225
+ - test/operation/reject_test.rb
225
226
  - test/operation_test.rb
226
227
  - test/rails/controller_test.rb
227
228
  - test/rails/endpoint_test.rb
@@ -264,7 +265,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
264
265
  version: '0'
265
266
  requirements: []
266
267
  rubyforge_project:
267
- rubygems_version: 2.4.8
268
+ rubygems_version: 2.2.2
268
269
  signing_key:
269
270
  specification_version: 4
270
271
  summary: A new architecture for Rails.
@@ -276,6 +277,7 @@ test_files:
276
277
  - test/fixtures/cells.png
277
278
  - test/module_test.rb
278
279
  - test/operation/contract_test.rb
280
+ - test/operation/reject_test.rb
279
281
  - test/operation_test.rb
280
282
  - test/rails/controller_test.rb
281
283
  - test/rails/endpoint_test.rb
@@ -297,3 +299,4 @@ test_files:
297
299
  - test/test_helper.rb
298
300
  - test/uploaded_file_test.rb
299
301
  - test/worker_test.rb
302
+ has_rdoc: