ddc 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/CHANGELOG.md +5 -0
- data/lib/ddc/controller_builder.rb +3 -1
- data/lib/ddc/response_builder.rb +10 -0
- data/lib/ddc/service_builder.rb +23 -3
- data/lib/ddc/version.rb +1 -1
- metadata +2 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f4965b4c204f8f2294d07ab1565ff8c4438e5545
|
4
|
+
data.tar.gz: 700d22532820d534e1d0d0b1a296f26e836f4695
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 498c59efdf922f09ae4b226444452a711f142b08b8308a605f28fdadcf62eb416efd7255ade2b6830550743ee10b5e5a737a4397eac1322edfecc04509fdb07c
|
7
|
+
data.tar.gz: 710fbeca96366bd9d0e38b057a13a1ea430e18cb6f892ad110d6a636f474f7c813d01e324c9dcc1308b4331139b7283525b815abaca603d1b75e3bb1b662e9ff
|
data/CHANGELOG.md
CHANGED
data/lib/ddc/response_builder.rb
CHANGED
@@ -3,11 +3,21 @@ module DDC
|
|
3
3
|
def not_found
|
4
4
|
{status: :not_found}
|
5
5
|
end
|
6
|
+
|
6
7
|
def ok(obj)
|
7
8
|
{status: :ok, object: obj}
|
8
9
|
end
|
10
|
+
|
9
11
|
def created(obj)
|
10
12
|
{status: :created, object: obj}
|
11
13
|
end
|
14
|
+
|
15
|
+
def not_valid(obj)
|
16
|
+
{status: :not_valid, object: obj, errors: obj.errors.to_hash}
|
17
|
+
end
|
18
|
+
|
19
|
+
def deleted(obj)
|
20
|
+
{status: :deleted}
|
21
|
+
end
|
12
22
|
end
|
13
23
|
end
|
data/lib/ddc/service_builder.rb
CHANGED
@@ -40,8 +40,12 @@ module DDC
|
|
40
40
|
me = self.class.ar_model.where id: id
|
41
41
|
|
42
42
|
if me.present?
|
43
|
-
me.update_attributes translated_updates
|
44
|
-
|
43
|
+
success = me.update_attributes translated_updates
|
44
|
+
if success
|
45
|
+
ok(me)
|
46
|
+
else
|
47
|
+
not_valid(me)
|
48
|
+
end
|
45
49
|
else
|
46
50
|
not_found
|
47
51
|
end
|
@@ -50,7 +54,23 @@ module DDC
|
|
50
54
|
def create(context)
|
51
55
|
attributes = context.values_at self.class.model_type
|
52
56
|
me = self.class.ar_model.create attributes
|
53
|
-
|
57
|
+
if me.persisted?
|
58
|
+
created(me)
|
59
|
+
else
|
60
|
+
not_valid(me)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def delete(context)
|
65
|
+
id = context[:id]
|
66
|
+
me = custom_finder ? custom_finder.find(context) :
|
67
|
+
ar_model.where(id: id)
|
68
|
+
if me.present?
|
69
|
+
me.destroy
|
70
|
+
deleted
|
71
|
+
else
|
72
|
+
not_found
|
73
|
+
end
|
54
74
|
end
|
55
75
|
|
56
76
|
private
|
data/lib/ddc/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ddc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shawn Anderson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -144,4 +144,3 @@ test_files:
|
|
144
144
|
- spec/controller_builder_spec.rb
|
145
145
|
- spec/service_builder_spec.rb
|
146
146
|
- spec/spec_helper.rb
|
147
|
-
has_rdoc:
|