sqlcached_client 1.1.0 → 1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e1f725ac30395fee0332b228f2f7afba9a8e3f63
4
- data.tar.gz: 6c8f3618babaf1f18b1295d75bb86a89c84007ca
3
+ metadata.gz: c52edd2d96831a9e05941a287443c347dca26549
4
+ data.tar.gz: 7894d5099b83c363f9f462f8cf1ce6b5cfb9d3ec
5
5
  SHA512:
6
- metadata.gz: e7759cc739a2e3d14bc63c294b84cc1096ed7c97f877e4e86210d3e792bfc61e95cab515b7a7a0362e87aaab382cad539305e5caf0eaf0beacdd8aeb860a848b
7
- data.tar.gz: 26d535fd6114978514c5b726755bdfd69a30458955a31259ccfc4f86d6baf7dc1dde767f501e392c91cad7e7ffb62077f03e6eaba14e9705fb7998bb2bce9915
6
+ metadata.gz: 712a6ea0b897d0458db5c70bed329e2a03bf37469341fb9bc9bb3fc4c7f7fcd2b0c49f1cb4dd865eb31061767cebc8920f4056b049c37d7ca1b8fab37b47af8a
7
+ data.tar.gz: b8eb923e7b4a37f7ef28e620b60a5484bba080fcd94e8187bf895c5302d6cfd4050d7b4aee5430c640b125327f5b62a600dc212281c17c1159f3186f2cb3fd9f
@@ -17,7 +17,7 @@ module SqlcachedClient
17
17
 
18
18
  class << self
19
19
 
20
- attr_reader :variables
20
+ attr_reader :variables, :entity_class
21
21
 
22
22
  def add_variable(variable_name, predicate)
23
23
  raise "Invalid predicate" if !PREDICATES.include?(predicate)
@@ -32,9 +32,17 @@ module SqlcachedClient
32
32
  self.class.variables
33
33
  end
34
34
 
35
+ def entity_class
36
+ self.class.entity_class
37
+ end
38
+
39
+ def entity_namespace
40
+ entity_class.try(:entity_namespace)
41
+ end
42
+
35
43
  def to_query_format
36
44
  {
37
- name: name,
45
+ name: external_name,
38
46
  condition_values: Hash[
39
47
  variables.map { |v| [v.name, conditions[v.name]] }
40
48
  ]
@@ -43,12 +51,23 @@ module SqlcachedClient
43
51
 
44
52
  def to_save_format
45
53
  {
46
- name: name,
54
+ name: external_name,
47
55
  attachment: content,
48
56
  conditions: variables.map do |v|
49
57
  "#{v.name} #{v.predicate} #{conditions[v.name]}"
50
58
  end
51
59
  }
52
60
  end
61
+
62
+ private
63
+
64
+ def external_name
65
+ @external_name ||=
66
+ if prefix = entity_namespace.presence
67
+ "#{entity_namespace}::#{name}"
68
+ else
69
+ name
70
+ end
71
+ end
53
72
  end
54
73
  end
@@ -6,11 +6,14 @@ module SqlcachedClient
6
6
  module ClassMethods
7
7
 
8
8
  def has_attachment(name, &block)
9
+ entity_class = self
9
10
  @attachment_classes ||= {}
10
11
  @attachment_classes[name] =
11
12
  Class.new(Attachment) do
12
13
 
13
14
  @attachment_name = name
15
+ @entity_class = entity_class
16
+
14
17
  class << self
15
18
  attr_reader :attachment_name
16
19
  end
@@ -1,3 +1,3 @@
1
1
  module SqlcachedClient
2
- VERSION = "1.1.0"
2
+ VERSION = "1.1.1"
3
3
  end
@@ -65,4 +65,31 @@ describe SqlcachedClient::Attachment do
65
65
  end
66
66
  end
67
67
  end
68
+
69
+ describe :entity_class do
70
+ it "is class.entity_class" do
71
+ attachment = described_class.new(nil, {}, nil)
72
+ allow(described_class).to receive(:entity_class).and_return('foo')
73
+ expect(attachment.entity_class).to eq('foo')
74
+ end
75
+ end
76
+
77
+ describe :entity_namespace do
78
+ context "when entity_class is nil" do
79
+ it "is nil" do
80
+ attachment = described_class.new(nil, {}, nil)
81
+ allow(attachment).to receive(:entity_class).and_return(nil)
82
+ expect(attachment.entity_namespace).to be_nil
83
+ end
84
+ end
85
+
86
+ context "when entity_class is not nil" do
87
+ it "is entity_class.entity_namespace" do
88
+ attachment = described_class.new(nil, {}, nil)
89
+ allow(attachment).to receive(:entity_class).and_return(
90
+ double(entity_namespace: 'foo'))
91
+ expect(attachment.entity_namespace).to eq('foo')
92
+ end
93
+ end
94
+ end
68
95
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sqlcached_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roberto Maestroni