application_service 0.1.1 → 0.2.0

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: 2ea9d96c1487f20cee45f1421e59592512c26914
4
- data.tar.gz: b124d237c1c23b06537347244f0f2dc4f354351f
3
+ metadata.gz: a2ba3938b2707398961940cb759ff62513c3e979
4
+ data.tar.gz: 3701a47aba069f130b9ae0b263123bc8f7c7ed47
5
5
  SHA512:
6
- metadata.gz: 57cc688368a77a3c63f8460ed7d0c23377aa6755c1a8e4eb1de7fc0d71e260cb2270df93b5914257d6057ea7c82c0a3a871fb5eb7b387ba1247d9f85ba1b287f
7
- data.tar.gz: eca9f180b7396e01087c74f6226f0b1dcb14cce4de79ba5cc9f15978ea2b1463b2cbff1119ad92f9cef4bad109934247d4f2b1a5d08258fccdd2d765b19ccdab
6
+ metadata.gz: 484eb1e80e2af5cbbcefc1c8bc0a60047664d8abf4b1a36f077ea5f92cccaec698d297551d8a663c3cc3ffb1666e034078df829aad2fb206a2269e78fac0435c
7
+ data.tar.gz: 8b1295095f81155e29ffe0bb7d63b1819af83907af787b7f9df77b341311a03186edb2d91866588acf973fb6bbece74f17abad85279e11503449ce6e9ca6421b
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.2.0
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: application_service 0.1.1 ruby lib
5
+ # stub: application_service 0.2.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "application_service"
9
- s.version = "0.1.1"
9
+ s.version = "0.2.0"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Nathan Woodhull"]
14
- s.date = "2014-07-21"
14
+ s.date = "2014-08-20"
15
15
  s.description = "A service layer scaffold for rails apps extracted from Agra"
16
16
  s.email = "woodhull@gmail.com"
17
17
  s.extra_rdoc_files = [
@@ -46,6 +46,18 @@ class ApplicationService
46
46
  end
47
47
  end
48
48
 
49
+ def save!(obj)
50
+ @obj = obj
51
+ run_callbacks :save do
52
+ if @obj.new_record?
53
+ result = create!
54
+ else
55
+ result = update!
56
+ end
57
+ result
58
+ end
59
+ end
60
+
49
61
  def update_attributes(obj, params)
50
62
  @obj = obj
51
63
  @obj.assign_attributes(params)
@@ -68,6 +80,12 @@ class ApplicationService
68
80
 
69
81
  private
70
82
 
83
+ def create!
84
+ run_callbacks :create do
85
+ @obj.save!
86
+ end
87
+ end
88
+
71
89
  def create
72
90
  run_callbacks :create do
73
91
  @obj.save
@@ -80,6 +98,12 @@ class ApplicationService
80
98
  end
81
99
  end
82
100
 
101
+ def update!
102
+ run_callbacks :update do
103
+ @obj.save!
104
+ end
105
+ end
106
+
83
107
  def self.extract_callback_options(args, default_if_option)
84
108
  options = args.last.is_a?(Hash) ? args.pop : {}
85
109
  if options && options.has_key?(:if)
@@ -42,6 +42,34 @@ describe ApplicationService do
42
42
  end
43
43
  end
44
44
 
45
+ describe "#save!" do
46
+ it "should let you save an object" do
47
+ obj = double()
48
+ obj.stub(:new_record?).and_return(true)
49
+ obj.should_receive(:save!)
50
+ subject.save!(obj)
51
+ end
52
+
53
+ it "should trigger create" do
54
+ obj = double()
55
+ obj.stub(:new_record?).and_return(true)
56
+ obj.stub(:save!)
57
+
58
+ subject.should_receive(:create!)
59
+ subject.save!(obj)
60
+ end
61
+
62
+
63
+ it "should trigger update" do
64
+ obj = double()
65
+ obj.stub(:new_record?).and_return(false)
66
+ obj.stub(:save!)
67
+
68
+ subject.should_receive(:update!)
69
+ subject.save!(obj)
70
+ end
71
+ end
72
+
45
73
  describe "#update_attributes" do
46
74
  it "should trigger update" do
47
75
  obj = double()
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: application_service
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Woodhull
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-21 00:00:00.000000000 Z
11
+ date: 2014-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport