placid 0.0.5 → 0.0.6
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.
- data/History.md +6 -0
- data/README.md +12 -6
- data/lib/placid/helper.rb +4 -4
- data/lib/placid/model.rb +7 -4
- data/placid.gemspec +4 -1
- data/spec/placid_helper_spec.rb +3 -3
- metadata +5 -5
data/History.md
CHANGED
data/README.md
CHANGED
@@ -21,7 +21,7 @@ Define a subclass with the name of your REST model:
|
|
21
21
|
class Person < Placid::Model
|
22
22
|
end
|
23
23
|
|
24
|
-
and you'll get these class methods, and their REST equivalents:
|
24
|
+
and you'll get these class methods, and their REST equivalents, automatically:
|
25
25
|
|
26
26
|
Person.list # GET /people
|
27
27
|
Person.create(attrs) # POST /person (attrs)
|
@@ -43,9 +43,10 @@ different field name, you can specify it like this:
|
|
43
43
|
unique_id :email
|
44
44
|
end
|
45
45
|
|
46
|
-
The `Placid::Model` base class includes helper methods for basic HTTP requests
|
47
|
-
|
48
|
-
define on your model. For
|
46
|
+
The `Placid::Model` base class includes helper methods for basic HTTP requests,
|
47
|
+
the most important of which is `request`. You can use these from any model
|
48
|
+
instance, or call them from custom methods you define on your model. For
|
49
|
+
example:
|
49
50
|
|
50
51
|
class Person < Placid::Model
|
51
52
|
unique_id :email
|
@@ -57,8 +58,12 @@ define on your model. For example:
|
|
57
58
|
|
58
59
|
jenny = Person.new(:email => 'jenny@example.com')
|
59
60
|
|
61
|
+
Now, calling this:
|
62
|
+
|
60
63
|
jenny.add_phone('867-5309')
|
61
|
-
|
64
|
+
|
65
|
+
Is the same as:
|
66
|
+
|
62
67
|
jenny.request(:put, 'person', 'jenny@example.com', 'add_phone', '867-5309')
|
63
68
|
|
64
69
|
|
@@ -116,7 +121,8 @@ License
|
|
116
121
|
|
117
122
|
The MIT License
|
118
123
|
|
119
|
-
Copyright (c) 2012 Society for Human
|
124
|
+
Copyright (c) 2012 Eric Pierce, Automation Excellence, Society for Human
|
125
|
+
Resource Management
|
120
126
|
|
121
127
|
Permission is hereby granted, free of charge, to any person obtaining
|
122
128
|
a copy of this software and associated documentation files (the
|
data/lib/placid/helper.rb
CHANGED
@@ -21,15 +21,15 @@ module Placid
|
|
21
21
|
# URI-escaped.
|
22
22
|
#
|
23
23
|
# @example
|
24
|
-
#
|
25
|
-
#
|
24
|
+
# get_url('people', 'eric') #=> 'http://localhost/people/eric'
|
25
|
+
# get_url('a b', 'c:d') #=> 'http://localhost/a%20b/c%3Ad'
|
26
26
|
#
|
27
27
|
# @param [Array] path
|
28
28
|
# Parts of the path to request. These will be escaped and joined with '/'.
|
29
29
|
#
|
30
30
|
# @return [String]
|
31
31
|
#
|
32
|
-
def
|
32
|
+
def get_url(*path)
|
33
33
|
url = Placid::Config.rest_url.to_s.gsub(/\/$/, '')
|
34
34
|
joined_path = path.map { |p| escape(p) }.join('/')
|
35
35
|
return "#{url}/#{joined_path}"
|
@@ -62,7 +62,7 @@ module Placid
|
|
62
62
|
method = method.to_sym
|
63
63
|
params = path.extract_options!
|
64
64
|
params = {:params => params} if method == :get
|
65
|
-
rest_url =
|
65
|
+
rest_url = get_url(*path)
|
66
66
|
begin
|
67
67
|
response = RestClient.send(method, rest_url, params)
|
68
68
|
rescue RestClient::Exception => e
|
data/lib/placid/model.rb
CHANGED
@@ -82,6 +82,7 @@ module Placid
|
|
82
82
|
|
83
83
|
# Get or set the field name used for uniquely identifying instances of this
|
84
84
|
# model.
|
85
|
+
#
|
85
86
|
def self.unique_id(field=nil)
|
86
87
|
if field.nil?
|
87
88
|
return @unique_id || :id
|
@@ -104,7 +105,8 @@ module Placid
|
|
104
105
|
end
|
105
106
|
end
|
106
107
|
|
107
|
-
# Return a Model instance matching the given id
|
108
|
+
# Return a Model instance matching the given id. Sends a GET request to the
|
109
|
+
# REST API.
|
108
110
|
#
|
109
111
|
# @param [String] id
|
110
112
|
# Identifier for the model instance to fetch
|
@@ -116,7 +118,8 @@ module Placid
|
|
116
118
|
return self.new(json)
|
117
119
|
end
|
118
120
|
|
119
|
-
# Create a new model instance and return it.
|
121
|
+
# Create a new model instance and return it. Sends a POST request
|
122
|
+
# to the REST API.
|
120
123
|
#
|
121
124
|
# @param [Hash] attrs
|
122
125
|
# Attribute values for the new instance
|
@@ -130,7 +133,7 @@ module Placid
|
|
130
133
|
return obj
|
131
134
|
end
|
132
135
|
|
133
|
-
# Update an existing model instance.
|
136
|
+
# Update an existing model instance. Sends a PUT request to the REST API.
|
134
137
|
#
|
135
138
|
# @param [String] id
|
136
139
|
# Identifier of the model instance to update
|
@@ -146,7 +149,7 @@ module Placid
|
|
146
149
|
return obj
|
147
150
|
end
|
148
151
|
|
149
|
-
# Destroy a model instance.
|
152
|
+
# Destroy a model instance. Sends a DELETE request to the REST API.
|
150
153
|
#
|
151
154
|
# @param [String] id
|
152
155
|
# Identifier for the model instance to delete
|
data/placid.gemspec
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "placid"
|
3
|
-
s.version = "0.0.
|
3
|
+
s.version = "0.0.6"
|
4
4
|
s.summary = "Models from REST"
|
5
5
|
s.description = <<-EOS
|
6
|
+
Placid is an ActiveRecord-ish model using a REST API for storage. The REST API
|
7
|
+
can be any backend you choose or create yourself, provided it follows some basic
|
8
|
+
conventions.
|
6
9
|
EOS
|
7
10
|
s.authors = ["Eric Pierce"]
|
8
11
|
s.email = "epierce@automation-excellence.com"
|
data/spec/placid_helper_spec.rb
CHANGED
@@ -7,13 +7,13 @@ describe Placid::Helper do
|
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
|
-
describe "#
|
10
|
+
describe "#get_url" do
|
11
11
|
it "joins path components with '/'" do
|
12
|
-
|
12
|
+
get_url('foo', 'bar', 'baz').should == 'http://localhost/foo/bar/baz'
|
13
13
|
end
|
14
14
|
|
15
15
|
it "escapes path components to make them URI-safe" do
|
16
|
-
|
16
|
+
get_url('a b', 'c:d', 'e/f').should == 'http://localhost/a%20b/c%3Ad/e%2Ff'
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: placid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 6
|
10
|
+
version: 0.0.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Eric Pierce
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-
|
18
|
+
date: 2012-08-27 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: hashie
|
@@ -129,7 +129,7 @@ dependencies:
|
|
129
129
|
version: "0"
|
130
130
|
type: :development
|
131
131
|
version_requirements: *id008
|
132
|
-
description: ""
|
132
|
+
description: " Placid is an ActiveRecord-ish model using a REST API for storage. The REST API\n can be any backend you choose or create yourself, provided it follows some basic\n conventions.\n"
|
133
133
|
email: epierce@automation-excellence.com
|
134
134
|
executables: []
|
135
135
|
|