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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5def3272125e8d0a5f3bbcb3301d57a18d1c8e4e
4
- data.tar.gz: 747e5bba75ae446c8448936c8b5d691e96fa5464
3
+ metadata.gz: dc3e60e23bca41d0d857ae65662634c291e23b37
4
+ data.tar.gz: c69edbdbdf47dd0e233f79e5dac18aeeaecab191
5
5
  SHA512:
6
- metadata.gz: ead5de341dfe6f70187fb0fd06f0a90826eeb053cac2f04440dd2c2394b12da022319c5743c008f6f032ad5f717221034c2a29637c36f6eddc41872af0dd11d2
7
- data.tar.gz: 753db55e2e73981dc8d7daf089a4687474b831dcb7459aaa46ceeee477ac43b6e1ec2bee374e29cb3df82c3dbbc99d7fdfc15745db638133709d53e35021f4fe
6
+ metadata.gz: 6ddcedd238f098e276c693e75cb67f87bdee8eea27ad2a76ada6e402b004ea0e20c65712a5cc974d0e56db556809e25188f259738a08b146d6ae50a2374f0c3c
7
+ data.tar.gz: d30f14e112a4ef9967568658c7d433046c2f65b9a3aef3815a0ae8946fcca6cb6d8615b6dd874c04379dccb7e71a17671b76cac60ab7af6ebfb7b992661cf257
@@ -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) || "null"
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
- encode resolve(self.prefix + self.index, model, **arguments)
70
+ Path.join resolve(self.prefix + self.index, model, **arguments)
44
71
  end
45
72
 
46
73
  def prefix_path(model, **arguments)
47
- encode resolve(self.prefix, model, **arguments)
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].join('/')
103
+ @type = Path.join([klass.type, self.type])
85
104
  end
86
105
 
87
106
  def view(name, path = nil, klass: self, index: nil)
@@ -105,7 +105,7 @@ module Relaxo
105
105
  end
106
106
 
107
107
  def type
108
- @attributes[:type]
108
+ Path.new @attributes[:type]
109
109
  end
110
110
 
111
111
  def valid_type?
@@ -20,6 +20,6 @@
20
20
 
21
21
  module Relaxo
22
22
  module Model
23
- VERSION = "0.10.2"
23
+ VERSION = "0.10.3"
24
24
  end
25
25
  end
@@ -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.2
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-01-25 00:00:00.000000000 Z
11
+ date: 2018-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: relaxo