caser 0.0.1 → 0.0.2
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 +4 -4
- data/README.md +5 -5
- data/lib/caser/action.rb +5 -0
- data/lib/caser/version.rb +1 -1
- data/test/action_test.rb +10 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e21259b41ce295bfd3fa40dbc6c5dfda5da1806e
|
4
|
+
data.tar.gz: fa9a498b7530e99ad3751941f2f2020a1d702528
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b1d9580197158d74434aac3295cf4101e783658656beef6005127fdf2c8b710a7bed1eebb237719af492db06fcfd83f3ff58a2a0f1fa560729746af0294e5f2
|
7
|
+
data.tar.gz: cfaf1e3867f5c5980b6b7e6dbd4a4c7ab9623520eb3116c8374727129e0fc1649c92fd064b879c0e487812ecbaba2ec4a16e8694624fb135ee58330258d3df6a
|
data/README.md
CHANGED
@@ -22,12 +22,12 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
To create a basic use case, extend Caser::Action:
|
25
|
+
To create a basic use case, extend Caser::Action and implement after_initialize (any arity you like) and do_process:
|
26
26
|
|
27
27
|
class Api::CreateContact < Caser::Action
|
28
28
|
attr_accessor :user, params
|
29
|
-
def after_initialize
|
30
|
-
@user, @params =
|
29
|
+
def after_initialize(user, params)
|
30
|
+
@user, @params = user, params
|
31
31
|
end
|
32
32
|
|
33
33
|
def do_process
|
@@ -39,7 +39,7 @@ To create a basic use case, extend Caser::Action:
|
|
39
39
|
|
40
40
|
def valid?(params)
|
41
41
|
unless :whatever
|
42
|
-
errors <<
|
42
|
+
errors << "No, we're not going to do that"
|
43
43
|
return false
|
44
44
|
end
|
45
45
|
true
|
@@ -60,7 +60,7 @@ Here is typical usage in a controller:
|
|
60
60
|
These use cases also support call-back style usage:
|
61
61
|
|
62
62
|
def create
|
63
|
-
Api::CreateContact.new(current_user, params[:contact]) do |on
|
63
|
+
Api::CreateContact.new(current_user, params[:contact]) do |on|
|
64
64
|
on.success {|action| ... code for success case}
|
65
65
|
on.failure {|action| ... code for failure case}
|
66
66
|
end.process
|
data/lib/caser/action.rb
CHANGED
@@ -4,8 +4,10 @@ module Caser
|
|
4
4
|
class Action
|
5
5
|
include Observable
|
6
6
|
|
7
|
+
attr_reader :outcome
|
7
8
|
def initialize(*params)
|
8
9
|
@_callbacks = nil
|
10
|
+
@outcome = nil
|
9
11
|
yield @_callbacks = Callbacks.new if block_given?
|
10
12
|
after_initialize(*params)
|
11
13
|
end
|
@@ -46,5 +48,8 @@ module Caser
|
|
46
48
|
notify_observers(event)
|
47
49
|
end
|
48
50
|
|
51
|
+
def set_outcome(outcome)
|
52
|
+
@outcome = outcome
|
53
|
+
end
|
49
54
|
end
|
50
55
|
end
|
data/lib/caser/version.rb
CHANGED
data/test/action_test.rb
CHANGED
@@ -3,13 +3,15 @@ require 'caser'
|
|
3
3
|
|
4
4
|
describe Caser::Action do
|
5
5
|
class BasicAction < Caser::Action
|
6
|
-
attr_accessor :will_fail
|
7
|
-
def after_initialize(will_fail = false)
|
6
|
+
attr_accessor :will_fail, :eventual_outcome
|
7
|
+
def after_initialize(will_fail = false, eventual_outcome = eventual_outcome)
|
8
8
|
@will_fail = will_fail
|
9
|
+
@eventual_outcome = eventual_outcome
|
9
10
|
end
|
10
11
|
|
11
12
|
def do_process
|
12
13
|
errors << "It failed" if will_fail?
|
14
|
+
set_outcome(eventual_outcome) if eventual_outcome
|
13
15
|
end
|
14
16
|
|
15
17
|
def will_fail?
|
@@ -38,6 +40,12 @@ describe Caser::Action do
|
|
38
40
|
@action = BasicAction.new(true).process
|
39
41
|
@action.errors.length.must_equal 1
|
40
42
|
end
|
43
|
+
|
44
|
+
it 'provides an outcome accessor' do
|
45
|
+
@outcome = Object.new
|
46
|
+
@action = BasicAction.new(true, @outcome).process
|
47
|
+
@action.outcome.must_equal @outcome
|
48
|
+
end
|
41
49
|
end
|
42
50
|
|
43
51
|
describe 'callback style' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: caser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Simon Robson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-10-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|