eipiai 0.2.0 → 0.3.0
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 +4 -4
- data/CHANGELOG.md +8 -0
- data/lib/eipiai/roar/representers/api.rb +2 -13
- data/lib/eipiai/roar/representers/base.rb +87 -0
- data/lib/eipiai/roar.rb +1 -0
- data/lib/eipiai/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0629a9a7ce30f972af6469dccc21f41afb350bbd
|
4
|
+
data.tar.gz: 9cedc4a8d4edebf85ca77daac499dc60ce07aed1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e40edbacb00400a7feeda253f4d211a06246db177d306d6aea94919a8efee8d6188cfdba7a3767f687c2bf9cbd085c3400157886113767ddd0a981c39cf9b815
|
7
|
+
data.tar.gz: f8e8583a01787c39a248025f435fa5fa9f93b112638624fcf3a446ce262a511ee4225af0f7ef4ad229d54c25582453f77748ce78f3e5847430de8f60b80b238a
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## [v0.2.0](https://github.com/blendle/eipiai/tree/v0.2.0) (2015-12-13)
|
4
|
+
[Full Changelog](https://github.com/blendle/eipiai/compare/v0.1.0...v0.2.0)
|
5
|
+
|
6
|
+
**Merged pull requests:**
|
7
|
+
|
8
|
+
- add tests for malformed\_request? and unprocessable\_entity? [\#3](https://github.com/blendle/eipiai/pull/3) ([JeanMertz](https://github.com/JeanMertz))
|
9
|
+
- initial validation implementation [\#2](https://github.com/blendle/eipiai/pull/2) ([JeanMertz](https://github.com/JeanMertz))
|
10
|
+
|
3
11
|
## [v0.1.0](https://github.com/blendle/eipiai/tree/v0.1.0) (2015-12-12)
|
4
12
|
**Merged pull requests:**
|
5
13
|
|
@@ -1,7 +1,4 @@
|
|
1
|
-
require '
|
2
|
-
require 'roar'
|
3
|
-
require 'roar/decorator'
|
4
|
-
require 'roar/json/hal'
|
1
|
+
require 'eipiai/roar/representers/base'
|
5
2
|
|
6
3
|
module Eipiai
|
7
4
|
# ApiRepresenter
|
@@ -11,11 +8,7 @@ module Eipiai
|
|
11
8
|
# tells the client if the route is templated or not.
|
12
9
|
#
|
13
10
|
class ApiRepresenter < Roar::Decorator
|
14
|
-
include
|
15
|
-
|
16
|
-
link(:self) do |request|
|
17
|
-
request.present? ? Addressable::URI.parse(request.uri).merge(path: path).to_s : path
|
18
|
-
end
|
11
|
+
include Eipiai::Representer
|
19
12
|
|
20
13
|
def self.populate_from_app(app)
|
21
14
|
app.routes.each do |route|
|
@@ -36,9 +29,5 @@ module Eipiai
|
|
36
29
|
request.present? ? Addressable::URI.parse(request.uri).merge(path: path).to_s : path
|
37
30
|
end
|
38
31
|
end
|
39
|
-
|
40
|
-
def path
|
41
|
-
'/api'
|
42
|
-
end
|
43
32
|
end
|
44
33
|
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'addressable/uri'
|
2
|
+
require 'roar'
|
3
|
+
require 'roar/decorator'
|
4
|
+
require 'roar/json/hal'
|
5
|
+
|
6
|
+
module Eipiai
|
7
|
+
# Representer
|
8
|
+
#
|
9
|
+
# The base Representer which all representers should include.
|
10
|
+
#
|
11
|
+
module Representer
|
12
|
+
def self.included(base)
|
13
|
+
base.include(Roar::JSON::HAL)
|
14
|
+
base.include(ClassMethods)
|
15
|
+
end
|
16
|
+
|
17
|
+
# path
|
18
|
+
#
|
19
|
+
# The path of the represented object, based on the representer name, and the
|
20
|
+
# object being represented.
|
21
|
+
#
|
22
|
+
# Given `UserItemRepresenter`, the following parts are assembled:
|
23
|
+
# * '/user'
|
24
|
+
# * `/user/{user_uid}` if object responds to `user_uid`
|
25
|
+
# * `/user/{user_uid}/item` (or `/user/item`)
|
26
|
+
# * `/user/{user_uid}/item/{uid}` if object responds to `uid`
|
27
|
+
#
|
28
|
+
# @example
|
29
|
+
# user = User.new(uid: 'bartsimpson')
|
30
|
+
# UserRepresenter.new(user).path # => '/user/bartsimpson'
|
31
|
+
#
|
32
|
+
# @example
|
33
|
+
# UserRepresenter.new(nil).path # => '/user'
|
34
|
+
#
|
35
|
+
# @return [String] the path of the represented object
|
36
|
+
#
|
37
|
+
def path
|
38
|
+
parts = path_parts.map { |part| part_path(part) }
|
39
|
+
File.join(*parts)
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
# part_path
|
45
|
+
#
|
46
|
+
# String representing the path of a "part".
|
47
|
+
#
|
48
|
+
# If part is "user", path_part will be `/user`, or `/user/{user_uid}` if the
|
49
|
+
# represented object responds to `user_uid`.
|
50
|
+
#
|
51
|
+
# @param [String] part of the object path
|
52
|
+
# @return [String] path of the part
|
53
|
+
#
|
54
|
+
def part_path(part)
|
55
|
+
var = (part == path_parts.last) ? 'uid' : "#{part}_uid"
|
56
|
+
uid = represented.respond_to?(var) ? represented.send(var) : nil
|
57
|
+
|
58
|
+
File.join(*['', part, uid].compact)
|
59
|
+
end
|
60
|
+
|
61
|
+
# path_parts
|
62
|
+
#
|
63
|
+
# Returns an array of "path parts", based on the representer name.
|
64
|
+
#
|
65
|
+
# If representer is named `UserItemRepresenter`, `path_parts` returns an
|
66
|
+
# array of `['user', 'item']`.
|
67
|
+
#
|
68
|
+
# @return [Array<String>] array of path parts
|
69
|
+
#
|
70
|
+
def path_parts
|
71
|
+
self.class.name.demodulize.chomp('Representer').underscore.split('_')
|
72
|
+
end
|
73
|
+
|
74
|
+
# ClassMethods
|
75
|
+
#
|
76
|
+
# These methods will be defined on the class in which this module is
|
77
|
+
# included.
|
78
|
+
#
|
79
|
+
module ClassMethods
|
80
|
+
include Roar::JSON::HAL
|
81
|
+
|
82
|
+
link(:self) do |request|
|
83
|
+
request.present? ? Addressable::URI.parse(request.uri).merge(path: path).to_s : path
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
data/lib/eipiai/roar.rb
CHANGED
data/lib/eipiai/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eipiai
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jean Mertz
|
@@ -244,6 +244,7 @@ files:
|
|
244
244
|
- lib/eipiai.rb
|
245
245
|
- lib/eipiai/roar.rb
|
246
246
|
- lib/eipiai/roar/representers/api.rb
|
247
|
+
- lib/eipiai/roar/representers/base.rb
|
247
248
|
- lib/eipiai/validation.rb
|
248
249
|
- lib/eipiai/validation/concerns/formatted_errors.rb
|
249
250
|
- lib/eipiai/validation/validators/base.rb
|