relaxo-model 0.10.2 → 0.10.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/relaxo/model/base.rb +31 -12
- data/lib/relaxo/model/document.rb +1 -1
- data/lib/relaxo/model/version.rb +1 -1
- data/spec/relaxo/model/document_spec.rb +8 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc3e60e23bca41d0d857ae65662634c291e23b37
|
4
|
+
data.tar.gz: c69edbdbdf47dd0e233f79e5dac18aeeaecab191
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ddcedd238f098e276c693e75cb67f87bdee8eea27ad2a76ada6e402b004ea0e20c65712a5cc974d0e56db556809e25188f259738a08b146d6ae50a2374f0c3c
|
7
|
+
data.tar.gz: d30f14e112a4ef9967568658c7d433046c2f65b9a3aef3815a0ae8946fcca6cb6d8615b6dd874c04379dccb7e71a17671b76cac60ab7af6ebfb7b992661cf257
|
data/lib/relaxo/model/base.rb
CHANGED
@@ -23,12 +23,39 @@ require 'uri'
|
|
23
23
|
|
24
24
|
module Relaxo
|
25
25
|
module Model
|
26
|
+
# A string that won't be escaped when concatenating with a path:
|
27
|
+
class Path < String
|
28
|
+
ENCODE = {'/' => '%2F', '%' => '%25'}
|
29
|
+
|
30
|
+
def to_s
|
31
|
+
self
|
32
|
+
end
|
33
|
+
|
34
|
+
def to_str
|
35
|
+
self
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.join(path)
|
39
|
+
joined_path = path.map do |part|
|
40
|
+
part = part.to_s
|
41
|
+
|
42
|
+
if part.is_a? Path
|
43
|
+
part
|
44
|
+
else
|
45
|
+
part.to_s.gsub(/[\/%]/, ENCODE)
|
46
|
+
end
|
47
|
+
end.join('/')
|
48
|
+
|
49
|
+
return self.new(joined_path)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
26
53
|
Key = Struct.new(:prefix, :index) do
|
27
54
|
def resolve(key_path, model, **arguments)
|
28
55
|
key_path.collect do |component|
|
29
56
|
case component
|
30
57
|
when Symbol
|
31
|
-
arguments[component] || model.send(component) ||
|
58
|
+
arguments[component] || model.send(component) || 'null'
|
32
59
|
when Array
|
33
60
|
resolve(component, model, arguments).join('-')
|
34
61
|
when Proc
|
@@ -40,19 +67,11 @@ module Relaxo
|
|
40
67
|
end
|
41
68
|
|
42
69
|
def object_path(model, **arguments)
|
43
|
-
|
70
|
+
Path.join resolve(self.prefix + self.index, model, **arguments)
|
44
71
|
end
|
45
72
|
|
46
73
|
def prefix_path(model, **arguments)
|
47
|
-
|
48
|
-
end
|
49
|
-
|
50
|
-
private
|
51
|
-
|
52
|
-
ENCODE = {'/' => '%2F', '%' => '%25'}
|
53
|
-
|
54
|
-
def encode(path)
|
55
|
-
path.collect{|part| part.to_s.gsub(/[\/%]/, ENCODE)}.join('/')
|
74
|
+
Path.join resolve(self.prefix, model, **arguments)
|
56
75
|
end
|
57
76
|
end
|
58
77
|
|
@@ -81,7 +100,7 @@ module Relaxo
|
|
81
100
|
attr :primary_key
|
82
101
|
|
83
102
|
def parent_type klass
|
84
|
-
@type = [klass.type, self.type]
|
103
|
+
@type = Path.join([klass.type, self.type])
|
85
104
|
end
|
86
105
|
|
87
106
|
def view(name, path = nil, klass: self, index: nil)
|
data/lib/relaxo/model/version.rb
CHANGED
@@ -78,6 +78,10 @@ RSpec.describe Relaxo::Model::Document do
|
|
78
78
|
expect(Invoice.all(database.current).count).to be == 3
|
79
79
|
end
|
80
80
|
|
81
|
+
it "should have resolved type" do
|
82
|
+
expect(Invoice::Transaction.type).to be_a Relaxo::Model::Path
|
83
|
+
end
|
84
|
+
|
81
85
|
it "should create model indexes" do
|
82
86
|
database.commit(message: "Adding test model") do |dataset|
|
83
87
|
invoice = Invoice.create(dataset, name: "Software Development")
|
@@ -94,7 +98,11 @@ RSpec.describe Relaxo::Model::Document do
|
|
94
98
|
expect(invoice).to_not be nil
|
95
99
|
|
96
100
|
transactions = Invoice::Transaction.by_invoice(database.current, invoice: invoice)
|
101
|
+
expect(transactions.path).to be == "invoice/transaction/by_invoice/invoice/#{invoice.id}"
|
97
102
|
expect(transactions).to_not be_empty
|
103
|
+
|
104
|
+
transaction = transactions.first
|
105
|
+
expect(transaction.to_s).to be == "invoice/transaction/#{transaction.id}"
|
98
106
|
end
|
99
107
|
|
100
108
|
it "updates indexes correctly" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: relaxo-model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.10.
|
4
|
+
version: 0.10.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-02-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: relaxo
|