rom 3.3.1 → 3.3.2

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: 2c8052ad74ae5b51b3c93fdf26f763c9b4311c03
4
- data.tar.gz: 7b08d6d109408b867d9835091f2659113677d9f0
3
+ metadata.gz: 351889d2541ad18d05c029e555b635919c68c50c
4
+ data.tar.gz: c66be9ee892b0ee4c4f2c7ec6505739d9a811df1
5
5
  SHA512:
6
- metadata.gz: 104cc004f3767ad8ce1907597ef7d93b2eca030517cacc174830c391ce64e09f367980b0f6d271be535286c2cbd4fb949bae1d656b32b604011b353450abf5ff
7
- data.tar.gz: c82137cf1b58dfa77ac280b0847c78625eb0fd86f0da3d416f71b2cf5340f9342703086d40681b482813ca0d2be10461db3c04c044133bf6b975e435ce7ac039
6
+ metadata.gz: 451aa0e25642c399e67eda6cddd8db5c67b801bbea371f291094913d693e9f226ed5defe783df59dfebebf4b1fd67a3577096df13c91a63faec8a2260bf0eeed
7
+ data.tar.gz: 41db751db49169072c52b16ffd07f4cbd694463dd2a64b484553d1a9542e47db81492b17d0e1914e489c4cf02dfa8f49ffd4bad905f271b4fc45177c760b7580
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ # v3.3.2 2017-10-14
2
+
3
+ ### Fixed
4
+
5
+ * Delegate private method calls in composite relations (flash-gordon)
6
+
7
+ [Compare v3.3.1...v3.3.2](https://github.com/rom-rb/rom/compare/v3.3.1...v3.3.2)
8
+
1
9
  # v3.3.1 2017-07-09
2
10
 
3
11
  ### Fixed
data/lib/rom/pipeline.rb CHANGED
@@ -94,6 +94,8 @@ module ROM
94
94
  #
95
95
  # @api private
96
96
  class Composite
97
+ (Kernel.private_instance_methods - %i(respond_to_missing?)).each(&method(:undef_method))
98
+
97
99
  include Dry::Equalizer(:left, :right)
98
100
  include Proxy
99
101
 
data/lib/rom/types.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'dry-types'
2
+ require 'json'
2
3
 
3
4
  module ROM
4
5
  module Types
@@ -6,6 +7,10 @@ module ROM
6
7
 
7
8
  def self.included(other)
8
9
  other.extend(Methods)
10
+ other::Coercible.extend(CoercibleMethods)
11
+ other::Coercible.const_set('JSON', other::Coercible.JSON)
12
+ other::Coercible.const_set('JSONHash', other::Coercible.JSONHash)
13
+ other::Coercible.const_set('HashJSON', other::Coercible.HashJSON)
9
14
  super
10
15
  end
11
16
 
@@ -22,5 +27,30 @@ module ROM
22
27
  type.meta(foreign_key: true, target: relation)
23
28
  end
24
29
  end
30
+
31
+ module CoercibleMethods
32
+ def JSONHash(symbol_keys: false, type: Types::Hash)
33
+ Types.Constructor(type) do |value|
34
+ next Hash[value] if value.respond_to?(:to_hash)
35
+
36
+ begin
37
+ ::JSON.parse(value.to_s, symbolize_names: symbol_keys)
38
+ rescue ::JSON::ParserError
39
+ value
40
+ end
41
+ end
42
+ end
43
+
44
+ def HashJSON(type: Types::String)
45
+ Types.Constructor(type) do |value|
46
+ next value unless value.respond_to?(:to_hash)
47
+ ::JSON.dump(value)
48
+ end
49
+ end
50
+
51
+ def JSON(symbol_keys: false)
52
+ self.HashJSON.meta(read: self.JSONHash(symbol_keys: symbol_keys))
53
+ end
54
+ end
25
55
  end
26
56
  end
data/lib/rom/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module ROM
2
- VERSION = '3.3.1'.freeze
2
+ VERSION = '3.3.2'.freeze
3
3
  end
@@ -6,6 +6,11 @@ RSpec.describe ROM::Relation::Composite do
6
6
 
7
7
  let(:users_relation) do
8
8
  Class.new(ROM::Memory::Relation) do
9
+ schema do
10
+ attribute :name, ROM::Types::String
11
+ attribute :email, ROM::Types::String
12
+ end
13
+
9
14
  def by_name(name)
10
15
  restrict(name: name)
11
16
  end
@@ -13,6 +18,10 @@ RSpec.describe ROM::Relation::Composite do
13
18
  def sorted(other)
14
19
  other.source.order(:name)
15
20
  end
21
+
22
+ def select(key)
23
+ project(key)
24
+ end
16
25
  end.new(users_dataset)
17
26
  end
18
27
 
@@ -86,4 +95,12 @@ RSpec.describe ROM::Relation::Composite do
86
95
  expect(relation.first).to eql('JOE')
87
96
  end
88
97
  end
98
+
99
+ describe '#__send__' do
100
+ it 'proxies Kernel methods' do
101
+ relation = (users_relation >> name_list >> upcaser).__send__(:select, :name)
102
+
103
+ expect(relation.call).to match_array(%w(JANE JOE))
104
+ end
105
+ end
89
106
  end
@@ -81,6 +81,91 @@ RSpec.describe ROM::Relation, '.schema' do
81
81
  expect(schema.foreign_key(:users)).to be(schema[:author_id])
82
82
  end
83
83
 
84
+ it 'allows JSON read/write coersion', aggregate_failures: true do
85
+ class Test::Posts < ROM::Relation[:memory]
86
+ schema do
87
+ attribute :payload, Types::Coercible::JSON
88
+ end
89
+ end
90
+
91
+ schema = Test::Posts.schema
92
+ json_payload = '{"foo":"bar"}'
93
+ hash_payload = { "foo" => "bar" }
94
+
95
+ expect(schema[:payload][hash_payload]).to eq(json_payload)
96
+ expect(schema[:payload].meta[:read][json_payload]).to eq(hash_payload)
97
+ end
98
+
99
+ it 'allows JSON/Hash read/write coersion using symbols as keys', aggregate_failures: true do
100
+ class Test::Posts < ROM::Relation[:memory]
101
+ schema do
102
+ attribute :payload, Types::Coercible::JSON(symbol_keys: true)
103
+ end
104
+ end
105
+
106
+ schema = Test::Posts.schema
107
+ json_payload = '{"foo":"bar"}'
108
+ hash_payload = { foo: "bar" }
109
+
110
+ expect(schema[:payload][hash_payload]).to eq(json_payload)
111
+ expect(schema[:payload].meta[:read][json_payload]).to eq(hash_payload)
112
+ end
113
+
114
+ it 'allows JSON to Hash coersion only' do
115
+ class Test::Posts < ROM::Relation[:memory]
116
+ schema do
117
+ attribute :payload, Types::Coercible::JSONHash
118
+ end
119
+ end
120
+
121
+ schema = Test::Posts.schema
122
+ json_payload = '{"foo":"bar"}'
123
+ hash_payload = { "foo" => "bar" }
124
+
125
+ expect(schema[:payload][json_payload]).to eq(hash_payload)
126
+ end
127
+
128
+ it 'returns original payload in JSON to Hash coersion when json is invalid' do
129
+ class Test::Posts < ROM::Relation[:memory]
130
+ schema do
131
+ attribute :payload, Types::Coercible::JSONHash
132
+ end
133
+ end
134
+
135
+ schema = Test::Posts.schema
136
+ json_payload = 'invalid: json'
137
+
138
+ expect(schema[:payload][json_payload]).to eq(json_payload)
139
+ end
140
+
141
+ it 'allows JSON to Hash coersion only using symbols as keys' do
142
+ class Test::Posts < ROM::Relation[:memory]
143
+ schema do
144
+ attribute :payload, Types::Coercible::JSONHash(symbol_keys: true)
145
+ end
146
+ end
147
+
148
+ schema = Test::Posts.schema
149
+ json_payload = '{"foo":"bar"}'
150
+ hash_payload = { foo: "bar" }
151
+
152
+ expect(schema[:payload][json_payload]).to eq(hash_payload)
153
+ end
154
+
155
+ it 'allows Hash to JSON coersion only' do
156
+ class Test::Posts < ROM::Relation[:memory]
157
+ schema do
158
+ attribute :payload, Types::Coercible::HashJSON
159
+ end
160
+ end
161
+
162
+ schema = Test::Posts.schema
163
+ json_payload = '{"foo":"bar"}'
164
+ hash_payload = { "foo" => "bar" }
165
+
166
+ expect(schema[:payload][hash_payload]).to eq(json_payload)
167
+ end
168
+
84
169
  it 'sets register_as and dataset' do
85
170
  class Test::Users < ROM::Relation[:memory]
86
171
  schema(:users) do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rom
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.1
4
+ version: 3.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Solnica
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-09 00:00:00.000000000 Z
11
+ date: 2017-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -401,7 +401,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
401
401
  version: '0'
402
402
  requirements: []
403
403
  rubyforge_project:
404
- rubygems_version: 2.6.12
404
+ rubygems_version: 2.6.13
405
405
  signing_key:
406
406
  specification_version: 4
407
407
  summary: Ruby Object Mapper