path-builder 0.1.0 → 0.1.1
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/README.md +22 -11
- data/lib/path-builder.rb +1 -14
- data/lib/path-builder/version.rb +1 -1
- data/path-builder-0.1.0.gem +0 -0
- 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: 521f007f861ad8a9ff775ba70b651d3d18a17e2c
|
4
|
+
data.tar.gz: 469021e9173cb59262c58d2aac16dd76b69be95a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 20d6995c38f238cdc70c653bf3f6aa4afa46d70c90f4f297acfa99f7c93259c972082138097a1d486987379b384461bc0c825ad0b05b1bf57f8bad6328269481
|
7
|
+
data.tar.gz: c54c9c562b57942cec723c81666827cca0ff939cc55a3344367e6104b7deb0ae31510985779eaf54366e7d5a43ef95cfe015245925df6c59c32a2548e7929020
|
data/README.md
CHANGED
@@ -32,22 +32,22 @@ path = PathBuilder.new
|
|
32
32
|
path.api.moo.to_s #=> 'api/moo/'
|
33
33
|
```
|
34
34
|
|
35
|
-
|
35
|
+
Make it variable:
|
36
36
|
```ruby
|
37
37
|
path = PathBuilder.new
|
38
38
|
path.api.(:version).moo.to_s('v1') #=> 'api/v1/moo/'
|
39
39
|
```
|
40
40
|
|
41
|
-
|
41
|
+
Why is that dot there? Because Ruby. Can we remove the dot? Yes, because Ruby:
|
42
42
|
```ruby
|
43
43
|
path = PathBuilder.new
|
44
|
-
path.api
|
44
|
+
path.api(:version).moo['v1'] #=> 'api/v1/moo/'
|
45
45
|
```
|
46
46
|
|
47
|
-
|
47
|
+
Or use `#[]` instead of `#to_s`:
|
48
48
|
```ruby
|
49
49
|
path = PathBuilder.new
|
50
|
-
path.api(:version).moo['v1'] #=> 'api/v1/moo/'
|
50
|
+
path.api.(:version).moo['v1'] #=> 'api/v1/moo/'
|
51
51
|
```
|
52
52
|
|
53
53
|
Use it out of the box:
|
@@ -58,8 +58,7 @@ PathBuilder.new.api(:version).moo['v1'] #=> 'api/v1/moo/'
|
|
58
58
|
Put in a url:
|
59
59
|
```ruby
|
60
60
|
path = PathBuilder.new
|
61
|
-
path[]
|
62
|
-
path.api(:version).moo.to_s #=> 'http://example.com/api/v1/moo'
|
61
|
+
path.('http://example.com').api(:version).moo[] #=> 'http://example.com/api/v1/moo/'
|
63
62
|
```
|
64
63
|
|
65
64
|
Reuse it:
|
@@ -80,7 +79,7 @@ UsersPath = ApiPath.users(:user_id).save!
|
|
80
79
|
|
81
80
|
UsersPath.new.to_s #=> 'api/v1/users/user_id/'
|
82
81
|
UsersPath.new.to_s(break_on_empty: true) #=> 'api/v1/users/'
|
83
|
-
UsersPath.new.to_s(1, break_on_empty: true) #=> 'api/v1/users/1'
|
82
|
+
UsersPath.new.to_s(1, break_on_empty: true) #=> 'api/v1/users/1/'
|
84
83
|
|
85
84
|
# Or just:
|
86
85
|
|
@@ -88,11 +87,23 @@ UsersPath.break_on_empty = true # PROTIP: You can set PathBuilder#break_on_empty
|
|
88
87
|
|
89
88
|
UsersPath.new[] #=> 'api/v1/users/'
|
90
89
|
UsersPath.new[nil] #=> 'api/v1/users/'
|
91
|
-
UsersPath.new['1'] #=> 'api/v1/users/1'
|
92
|
-
UsersPath.new.comments[] #=> 'api/v1/users'
|
90
|
+
UsersPath.new['1'] #=> 'api/v1/users/1/'
|
91
|
+
UsersPath.new.comments[] #=> 'api/v1/users/'
|
93
92
|
UsersPath.new.comments['1'] #=> 'api/v1/users/1/comments/'
|
94
93
|
UsersPath.new.comments(:comment_id).post['1'] #=> 'api/v1/users/1/comments/'
|
95
|
-
UsersPath.new.comments(:comment_id).post['1', '2'] #=> 'api/v1/users/1/comments/2/post'
|
94
|
+
UsersPath.new.comments(:comment_id).post['1', '2'] #=> 'api/v1/users/1/comments/2/post/'
|
95
|
+
```
|
96
|
+
|
97
|
+
Make a mistake? Take it away!
|
98
|
+
|
99
|
+
```ruby
|
100
|
+
path = UsersPath.new.comments(:comment_id).post.oops
|
101
|
+
path['1','2'] #=> 'api/v1/users/1/comments/2/post/oops/'
|
102
|
+
path - 1 #=> [:oops]
|
103
|
+
path['1', '2'] #=> 'api/v1/user/1/comments/2/post/'
|
104
|
+
path.oh.nose.this.shouldnt.be.here['1,2'] #=> 'api/v1/user/1/comments/2/post/oh/nose/this/shouldnt/be/here/'
|
105
|
+
path - 6 #=> [:oh, :nose, :this, :shouldnt, :be, :here]
|
106
|
+
path['1,2'] #=> #=> 'api/v1/user/1/comments/2/post/'
|
96
107
|
```
|
97
108
|
|
98
109
|
Curious on how it works? Read the 88 line [source].
|
data/lib/path-builder.rb
CHANGED
@@ -41,20 +41,7 @@ class PathBuilder
|
|
41
41
|
|
42
42
|
# Add a variable segment (symbol)
|
43
43
|
def call(segment)
|
44
|
-
@path << segment
|
45
|
-
self
|
46
|
-
end
|
47
|
-
|
48
|
-
# Add a segment (string)
|
49
|
-
def []=(*args)
|
50
|
-
if args.length = 1
|
51
|
-
segment = *args
|
52
|
-
@path << segment.to_s if segment
|
53
|
-
else
|
54
|
-
variable_segment, *segment = *args
|
55
|
-
@path << variable_segment.to_sym if variable_segment
|
56
|
-
@path += segment.map(&:to_s)
|
57
|
-
end
|
44
|
+
@path << segment
|
58
45
|
self
|
59
46
|
end
|
60
47
|
|
data/lib/path-builder/version.rb
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: path-builder
|
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
|
- Ben
|
@@ -55,6 +55,7 @@ files:
|
|
55
55
|
- bin/setup
|
56
56
|
- lib/path-builder.rb
|
57
57
|
- lib/path-builder/version.rb
|
58
|
+
- path-builder-0.1.0.gem
|
58
59
|
- path-builder.gemspec
|
59
60
|
homepage: https://github.com/penne12/path-builder
|
60
61
|
licenses:
|