served 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -2
- data/lib/served/resource/base.rb +16 -6
- data/lib/served/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 18d0b5a5d6bc54eed0cc6d6ff0485342c9487863
|
4
|
+
data.tar.gz: e4cd8e832643622713b0aa8d5343ebd451609b40
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 42193c7f1e6d2356244fd48894a9a254680cbeb3ffdd0a587346a223d013619dd85a9a40dcde6bac091e881fd004ea7ad74d5d33a44d0a6dcb7a4c96ac1d750b
|
7
|
+
data.tar.gz: 338753924c4f965a38d45db21b225439d70dac94092442e36ed66b05514a3518fe087c3fa95919b911c2847deb0a637c555cb1f16d134a8038d848bcf4b0ad52
|
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# Served
|
2
|
-
[](https://travis-ci.org/optoro/served)
|
3
3
|
|
4
4
|
Served is a gem in the vein of [ActiveResource](https://github.com/rails/activeresource) designed to facilitate
|
5
5
|
communication between distributed Rails services.
|
@@ -10,18 +10,25 @@ Add the following to your Gemfile:
|
|
10
10
|
|
11
11
|
```gem 'served'```
|
12
12
|
|
13
|
+
|
13
14
|
# Usage
|
15
|
+
A service model can be created by declaring a class inheriting from ```Service::Resource::Base```.
|
14
16
|
|
15
17
|
```ruby
|
16
18
|
class SomeService::SomeResource < Served::Resource::Base
|
17
19
|
|
18
20
|
attribute :name
|
19
21
|
attribute :date
|
20
|
-
attribute :phone_number
|
22
|
+
attribute :phone_number, default: '555-555-5555'
|
21
23
|
|
22
24
|
end
|
23
25
|
```
|
24
26
|
|
27
|
+
## Saving a resource
|
28
|
+
Served follows resourceful standards. When a resource is initially saved a **POST** request will be sent
|
29
|
+
to the service. When the resource already exists, a **PUT** request will be sent. Served determines if
|
30
|
+
a resource is new or not based on the presence of an id.
|
31
|
+
|
25
32
|
# Configuration
|
26
33
|
|
27
34
|
Served is configured using ```Served.config```.
|
data/lib/served/resource/base.rb
CHANGED
@@ -23,15 +23,15 @@ module Served
|
|
23
23
|
# class SomeResource
|
24
24
|
# attribute :attr1
|
25
25
|
# end
|
26
|
-
def attribute(name)
|
26
|
+
def attribute(name, options={})
|
27
27
|
return if attributes.include?(name)
|
28
|
-
attributes
|
28
|
+
attributes[name] = options
|
29
29
|
attr_accessor name
|
30
30
|
end
|
31
31
|
|
32
|
-
# @return [
|
32
|
+
# @return [Hash] declared attributes for the resources
|
33
33
|
def attributes
|
34
|
-
@attributes ||=
|
34
|
+
@attributes ||= {}
|
35
35
|
end
|
36
36
|
|
37
37
|
# Looks up a resource on the service by id. For example `SomeResource.find(5)` would call `/some_resources/5`
|
@@ -98,7 +98,7 @@ module Served
|
|
98
98
|
#
|
99
99
|
# @param [Boolean] with_values whether or not to return all attributes or only those whose values are not nil
|
100
100
|
def attributes
|
101
|
-
Hash[self.class.attributes.collect { |name| [name, send(name)] }]
|
101
|
+
Hash[self.class.attributes.keys.collect { |name| [name, send(name)] }]
|
102
102
|
end
|
103
103
|
|
104
104
|
# Reloads the resource using attributes from the service
|
@@ -141,7 +141,17 @@ module Served
|
|
141
141
|
|
142
142
|
|
143
143
|
def reload_with_attributes(attributes)
|
144
|
-
attributes.each
|
144
|
+
attributes.each do |name, value|
|
145
|
+
set_attribute(name.to_sym, value)
|
146
|
+
end
|
147
|
+
set_attribute_defaults
|
148
|
+
end
|
149
|
+
|
150
|
+
def set_attribute_defaults
|
151
|
+
self.class.attributes.each do |attr, options|
|
152
|
+
next if options[:default].nil? || send(attr)
|
153
|
+
set_attribute(attr, options[:default])
|
154
|
+
end
|
145
155
|
end
|
146
156
|
|
147
157
|
def set_attribute(name, value)
|
data/lib/served/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: served
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jarod Reid
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -125,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
125
125
|
version: '0'
|
126
126
|
requirements: []
|
127
127
|
rubyforge_project:
|
128
|
-
rubygems_version: 2.4.
|
128
|
+
rubygems_version: 2.4.7
|
129
129
|
signing_key:
|
130
130
|
specification_version: 4
|
131
131
|
summary: Served provides an easy to use model layer for communicating with disributed
|