uncouple 0.1.0 → 0.1.1

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: 928317f2195176bad12b1b7c6d46b7ad71b1482c
4
- data.tar.gz: d694b364a751cdae7dc60c7d0922ce825809eeda
3
+ metadata.gz: aa336a1a181a1dcf4fadce08625824b04de395cd
4
+ data.tar.gz: 8acdaf19fcf59852b73ac91df1c479aebd789812
5
5
  SHA512:
6
- metadata.gz: 62db4c8201c0616b2ff6c2eec3adff326db3b5f7522ff72f6128e71018f3d9d1f2132e65597c52ad35a3eca4c165628b657156a1711d7c8c999ab74f67d83c8e
7
- data.tar.gz: a39acbcfe9658e2446f603bd91c01a2ad0358e2efaba5d781ff98b33bfcecb15f50e0462cce8e32380233dc747f6c3387c776f1c56bc5d44c4e1446cd14ca770
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/slavery.svg?branch=master)](https://travis-ci.org/citrus/slavery)
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 rails.
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 < Metric::NewAction
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(@metric).deliver
58
+ NewMetricMailer.notification(metric).deliver
50
59
  end
51
60
 
52
61
  def success?
@@ -4,7 +4,7 @@ module Uncouple
4
4
  attr_reader :params
5
5
 
6
6
  def initialize(params=nil)
7
- @params = convert_to_strong_parameters(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 convert_to_strong_parameters(params)
24
+ def recast_parameters(params)
25
25
  return if params.nil?
26
- return params unless defined?(ActionController::Parameters)
27
- return params if params.is_a?(ActionController::Parameters)
28
- ActionController::Parameters.new(params)
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
@@ -1,3 +1,3 @@
1
1
  module Uncouple
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uncouple
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Spencer Steffen