uncouple 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +13 -4
- data/lib/uncouple/action.rb +17 -5
- data/lib/uncouple/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa336a1a181a1dcf4fadce08625824b04de395cd
|
4
|
+
data.tar.gz: 8acdaf19fcf59852b73ac91df1c479aebd789812
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16d8ff285865f617df7cebd73882af6256c028b9dec0bbfd5f66995d7d3cb6fdc03c1b25daf0740bb47893f65464cf27d95340f1292e3add8f00e434959cb515
|
7
|
+
data.tar.gz: 7466e07a10605deac628fac0890af012c20161631a2018eb65b60f4b5c01e3ec55e6fdb0f6f69ec3b0e1a826737a7c9c280b9d32625cdc1022776232fe14ecf6
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# Uncouple
|
2
2
|
|
3
|
-
[![Build Status](https://travis-ci.org/citrus/
|
3
|
+
[![Build Status](https://travis-ci.org/citrus/uncouple.svg?branch=master)](https://travis-ci.org/citrus/uncouple)
|
4
4
|
|
5
|
-
Uncouple your business logic from
|
5
|
+
Uncouple your business logic from Rails or whatever other framework you may be using.
|
6
6
|
|
7
7
|
|
8
8
|
## Installation
|
@@ -13,6 +13,13 @@ Add this line to your application's Gemfile:
|
|
13
13
|
gem 'uncouple'
|
14
14
|
```
|
15
15
|
|
16
|
+
If you're on rails:
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
gem 'uncouple', require: 'uncouple/rails'
|
20
|
+
```
|
21
|
+
|
22
|
+
|
16
23
|
And then execute:
|
17
24
|
|
18
25
|
$ bundle
|
@@ -34,7 +41,9 @@ Use actions to encapsulate your business logic.
|
|
34
41
|
|
35
42
|
```rb
|
36
43
|
# app/actions/metric/create_action.rb
|
37
|
-
class Metric::CreateAction <
|
44
|
+
class Metric::CreateAction < Uncouple::Action
|
45
|
+
|
46
|
+
attr_reader :metric
|
38
47
|
|
39
48
|
def perform
|
40
49
|
create_metric!
|
@@ -46,7 +55,7 @@ class Metric::CreateAction < Metric::NewAction
|
|
46
55
|
end
|
47
56
|
|
48
57
|
def notify!
|
49
|
-
NewMetricMailer.notification(
|
58
|
+
NewMetricMailer.notification(metric).deliver
|
50
59
|
end
|
51
60
|
|
52
61
|
def success?
|
data/lib/uncouple/action.rb
CHANGED
@@ -4,7 +4,7 @@ module Uncouple
|
|
4
4
|
attr_reader :params
|
5
5
|
|
6
6
|
def initialize(params=nil)
|
7
|
-
@params =
|
7
|
+
@params = recast_parameters(params)
|
8
8
|
end
|
9
9
|
|
10
10
|
def perform
|
@@ -21,11 +21,23 @@ module Uncouple
|
|
21
21
|
|
22
22
|
private
|
23
23
|
|
24
|
-
def
|
24
|
+
def recast_parameters(params)
|
25
25
|
return if params.nil?
|
26
|
-
|
27
|
-
|
28
|
-
|
26
|
+
if defined?(ActionController::Parameters)
|
27
|
+
recast_as_strong_parameters(params)
|
28
|
+
elsif defined?(ActiveSupport::HashWithIndifferentAccess)
|
29
|
+
recast_as_indifferent_parameters(params)
|
30
|
+
else
|
31
|
+
params
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def recast_as_strong_parameters(params)
|
36
|
+
params.is_a?(ActionController::Parameters) ? params : ActionController::Parameters.new(params)
|
37
|
+
end
|
38
|
+
|
39
|
+
def recast_as_indifferent_parameters(params)
|
40
|
+
params.is_a?(ActiveSupport::HashWithIndifferentAccess) ? params : ActiveSupport::HashWithIndifferentAccess.new(params)
|
29
41
|
end
|
30
42
|
|
31
43
|
end
|
data/lib/uncouple/version.rb
CHANGED