luna_park 0.13.0 → 0.13.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +2 -1
- data/Gemfile.lock +2 -2
- data/lib/luna_park/extensions/data_mapper.rb +8 -7
- data/lib/luna_park/extensions/repositories/postgres/create.rb +2 -2
- data/lib/luna_park/extensions/repositories/postgres/delete.rb +10 -2
- data/lib/luna_park/extensions/repositories/postgres/read.rb +9 -0
- data/lib/luna_park/extensions/repositories/postgres/update.rb +5 -3
- data/lib/luna_park/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '06428c4acf0f2aafb70f1bc68ab52335aab96c64408b1a3bbf12b0bebb840e82'
|
4
|
+
data.tar.gz: 24a00cd21ba73f3ed7244531c981d46ea542c9fb1734c2c67c54f83716064bf0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 482d49c124763eb9ca7f93225365abc348f5d83b9db98cd6b888304d3c7ecb824a7047f03e5f6eff47ab7c989158538d689b4a116c886d21ecfee2fe3fc97056
|
7
|
+
data.tar.gz: 23ed759b552c29608170b5c29db85e040822b3a546d205f7e8f25564c358f0cf713c7839aafaaa1a81476b74450a010174472933232c220b6b0e150bd6c34227
|
data/CHANGELOG.md
CHANGED
@@ -4,11 +4,12 @@ All notable changes to this project will be documented in this file.
|
|
4
4
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
5
5
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
6
6
|
|
7
|
-
## [0.13.
|
7
|
+
## [0.13.1] - 2023-12-06
|
8
8
|
Changed
|
9
9
|
- `Extensions::Repositories::Postgres::Delete` returns boolean
|
10
10
|
- DataMapper became more safe: it will raise `MoreThanOneRecord` if `#read_one` received array with multiple items,
|
11
11
|
so it will show you your critical logic mistake
|
12
|
+
- `Extensions::Repositories::Postgres::Delete#delete` can receive entity, Hash, and can not accept nil pk
|
12
13
|
|
13
14
|
Added
|
14
15
|
- `DataMapper.mapper` now can receive block instead of class, to describe anonymous mapper;
|
data/Gemfile.lock
CHANGED
@@ -145,7 +145,7 @@ module LunaPark
|
|
145
145
|
@mapper_class
|
146
146
|
end
|
147
147
|
|
148
|
-
def __build_entity_coercion__(coercion)
|
148
|
+
def __build_entity_coercion__(coercion)
|
149
149
|
return entity_class.method(coercion) if coercion.is_a? Symbol
|
150
150
|
return coercion if coercion.respond_to?(:call)
|
151
151
|
|
@@ -154,7 +154,7 @@ module LunaPark
|
|
154
154
|
infer_entity_coercion
|
155
155
|
end
|
156
156
|
|
157
|
-
def infer_entity_coercion
|
157
|
+
def infer_entity_coercion
|
158
158
|
return entity_class.method(:call) if entity_class.respond_to?(:call)
|
159
159
|
return entity_class.method(:wrap) if entity_class.respond_to?(:wrap)
|
160
160
|
|
@@ -179,13 +179,13 @@ module LunaPark
|
|
179
179
|
end
|
180
180
|
|
181
181
|
def primary_key(attr)
|
182
|
-
@
|
182
|
+
@row_primary_key = attr
|
183
183
|
end
|
184
184
|
|
185
185
|
DEFAULT_PRIMARY_KEY = :id
|
186
186
|
|
187
|
-
def
|
188
|
-
@
|
187
|
+
def row_primary_key
|
188
|
+
@row_primary_key || DEFAULT_PRIMARY_KEY
|
189
189
|
end
|
190
190
|
|
191
191
|
def __define_constants__(not_found: LunaPark::Extensions::DataMapper::NotFound)
|
@@ -201,6 +201,7 @@ module LunaPark
|
|
201
201
|
klass.__define_constants__(not_found: NotFound)
|
202
202
|
klass.entity entity_class, __entity_coercion__
|
203
203
|
klass.mapper mapper_class
|
204
|
+
klass.primary_key row_primary_key
|
204
205
|
super
|
205
206
|
end
|
206
207
|
|
@@ -264,7 +265,7 @@ module LunaPark
|
|
264
265
|
# end
|
265
266
|
#
|
266
267
|
def found!(value, not_found_by: nil)
|
267
|
-
return value unless value.nil?
|
268
|
+
return value unless value.nil? || value.respond_to?(:empty?) && value.empty?
|
268
269
|
|
269
270
|
raise self.class::NotFound.new name: self.class.entity_class.name, by: not_found_by
|
270
271
|
end
|
@@ -385,7 +386,7 @@ module LunaPark
|
|
385
386
|
# Read config
|
386
387
|
|
387
388
|
def primary_key
|
388
|
-
self.class.
|
389
|
+
self.class.row_primary_key
|
389
390
|
end
|
390
391
|
|
391
392
|
# Factory Methods
|
@@ -5,7 +5,7 @@ module LunaPark
|
|
5
5
|
module Repositories
|
6
6
|
module Postgres
|
7
7
|
module Create
|
8
|
-
def create(input)
|
8
|
+
def create(input, **scope_opts)
|
9
9
|
entity = wrap(input)
|
10
10
|
|
11
11
|
time = Time.now
|
@@ -13,7 +13,7 @@ module LunaPark
|
|
13
13
|
entity.updated_at = time if entity.respond_to?(:updated_at)
|
14
14
|
|
15
15
|
row = to_row(entity)
|
16
|
-
new_row =
|
16
|
+
new_row = scoped(**scope_opts).returning.insert(row).first
|
17
17
|
new_attrs = from_row(new_row)
|
18
18
|
|
19
19
|
entity.set_attributes(new_attrs)
|
@@ -5,8 +5,16 @@ module LunaPark
|
|
5
5
|
module Repositories
|
6
6
|
module Postgres
|
7
7
|
module Delete
|
8
|
-
def delete(
|
9
|
-
|
8
|
+
def delete(input, **scope_opts)
|
9
|
+
pk_value = case input
|
10
|
+
when self.class.entity_class then input.public_send(primary_key)
|
11
|
+
when Hash then input[primary_key]
|
12
|
+
else input
|
13
|
+
end
|
14
|
+
|
15
|
+
raise ArgumentError, "primary key '#{primary_key}' value can't be nil" if pk_value.nil?
|
16
|
+
|
17
|
+
scoped(**scope_opts).where(primary_key => pk_value).delete.positive?
|
10
18
|
end
|
11
19
|
end
|
12
20
|
end
|
@@ -25,6 +25,15 @@ module LunaPark
|
|
25
25
|
read_one scoped(**scope).where(primary_key => pk_value)
|
26
26
|
end
|
27
27
|
|
28
|
+
def reload!(entity, **scope)
|
29
|
+
new_rows = scoped(**scope).where(primary_key => entity.public_send(primary_key))
|
30
|
+
found! new_rows, not_found_by: { primary_key => entity.public_send(primary_key)}
|
31
|
+
|
32
|
+
new_attrs = from_row __one_from__ new_rows
|
33
|
+
entity.set_attributes(new_attrs)
|
34
|
+
entity
|
35
|
+
end
|
36
|
+
|
28
37
|
def count(**scope)
|
29
38
|
scoped(**scope).count
|
30
39
|
end
|
@@ -5,13 +5,15 @@ module LunaPark
|
|
5
5
|
module Repositories
|
6
6
|
module Postgres
|
7
7
|
module Update
|
8
|
-
def save(input)
|
8
|
+
def save(input, **scope_opts)
|
9
9
|
entity = wrap(input)
|
10
10
|
|
11
11
|
entity.updated_at = Time.now if entity.respond_to?(:updated_at)
|
12
12
|
|
13
|
-
row
|
14
|
-
new_row
|
13
|
+
row = to_row(entity)
|
14
|
+
new_row = scoped(**scope_opts).where(primary_key => row[primary_key]).returning.update(row).first
|
15
|
+
found! new_row, not_found_by: { primary_key => row[primary_key] }
|
16
|
+
|
15
17
|
new_attrs = from_row(new_row)
|
16
18
|
|
17
19
|
entity.set_attributes(new_attrs)
|
data/lib/luna_park/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: luna_park
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.13.
|
4
|
+
version: 0.13.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Kudrin
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2023-12-
|
12
|
+
date: 2023-12-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bugsnag
|