luna_park 0.13.0 → 0.13.2

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
  SHA256:
3
- metadata.gz: 3491b1852cab029d5f1b60cdc9ff638e2eac71a1d366e1463e31b7c6a4afa127
4
- data.tar.gz: f0b5abc0af74a11ac5d6e392def3daa5e565ac7ba5033315981013dae3f0734a
3
+ metadata.gz: 80b01a66294a4b81ecfb19e7ecbc5e94b2d90f105d7c05946dacc49298e84204
4
+ data.tar.gz: dd06fd03c3ab1a8a10e38aaeaf37ac74aa81b2a57d380b91c28c5888d34d50ec
5
5
  SHA512:
6
- metadata.gz: 25f821e41e63fcb3bfcc8744ea203b861360126cc7edc12f5032e7153831a514e527ef80e8453fc5b8f24e5bf5f458c88226f1103ab8bcf85249222d4c7355b5
7
- data.tar.gz: 903dd8923a134ea14d8f3611e3c803989f976f923e5b251cc65e47bef6cecc923173ae6654f2361ac2cc49190231d7d24c427d4144720abdbd9d0368b5ae386b
6
+ metadata.gz: 29655ccee48e0161dfd73820345d2544ed7e9639a8e327edf0034bd9a13639c9a615c66551a313692339752a071717f133f9c545b971ee97df967d86ab0884fe
7
+ data.tar.gz: 0eb1a328dd65005510f51c7c6e27e26706b19e0b50f252cbc3b0546ff324879e7f8653886b858210bbb0812992d1e308ba24c47b71a1b14fbecca86dfd62ce7f
data/CHANGELOG.md CHANGED
@@ -4,11 +4,16 @@ 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.0] - 2023-06-06
7
+ ## [0.13.2] - 2023-12-25
8
+ Added
9
+ - Ruby 3 compatibility (still compatible with ruby 2.5)
10
+
11
+ ## [0.13.1] - 2023-12-06
8
12
  Changed
9
13
  - `Extensions::Repositories::Postgres::Delete` returns boolean
10
14
  - DataMapper became more safe: it will raise `MoreThanOneRecord` if `#read_one` received array with multiple items,
11
15
  so it will show you your critical logic mistake
16
+ - `Extensions::Repositories::Postgres::Delete#delete` can receive entity, Hash, and can not accept nil pk
12
17
 
13
18
  Added
14
19
  - `DataMapper.mapper` now can receive block instead of class, to describe anonymous mapper;
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- luna_park (0.13.0)
4
+ luna_park (0.13.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -219,4 +219,4 @@ DEPENDENCIES
219
219
  yard (~> 0.9)
220
220
 
221
221
  BUNDLED WITH
222
- 2.2.30
222
+ 2.3.20
@@ -30,14 +30,14 @@ module LunaPark
30
30
  # MyCallableObject.call!(params) # => 'call! used'
31
31
  module Callable
32
32
  # Preferred class method to run instance `call` method
33
- def call(*args)
34
- new(*args).call
33
+ def call(*args, **kwargs)
34
+ new(*args, **kwargs).call
35
35
  end
36
36
 
37
37
  ##
38
38
  # Preferred class method to run instance `call`! method
39
- def call!(*args)
40
- new(*args).call!
39
+ def call!(*args, **kwargs)
40
+ new(*args, **kwargs).call!
41
41
  end
42
42
  end
43
43
  end
@@ -145,7 +145,7 @@ module LunaPark
145
145
  @mapper_class
146
146
  end
147
147
 
148
- def __build_entity_coercion__(coercion) # rubocop:disable Metrics/AbcSize
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 # rubocop:disable Metrics/AbcSize
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
- @primary_key_attr = attr
182
+ @row_primary_key = attr
183
183
  end
184
184
 
185
185
  DEFAULT_PRIMARY_KEY = :id
186
186
 
187
- def primary_key_attr
188
- @primary_key_attr || DEFAULT_PRIMARY_KEY
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.primary_key_attr
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 = dataset.returning.insert(row).first
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(uid)
9
- dataset.where(primary_key => uid).delete.positive?
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) # rubocop:disable Metrics/AbcSize
9
9
  entity = wrap(input)
10
10
 
11
11
  entity.updated_at = Time.now if entity.respond_to?(:updated_at)
12
12
 
13
- row = to_row(entity)
14
- new_row = dataset.where(primary_key => row[primary_key]).returning.update(row).first
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)
@@ -33,7 +33,7 @@ module LunaPark
33
33
  def wrap(input)
34
34
  case input
35
35
  when self then input
36
- when Hash then new(input)
36
+ when Hash then new(**input)
37
37
  when nil then nil
38
38
  else raise Errors::Unwrapable, "#{self} can not wrap #{input.class}"
39
39
  end
@@ -80,7 +80,7 @@ module LunaPark
80
80
  # @param [Hash] details - Any another details for current message
81
81
  def post(msg, lvl: :error, **details)
82
82
  severity = severity(lvl)
83
- message = serialize(msg, details)
83
+ message = serialize(msg, **details)
84
84
  logger.add severity, message
85
85
  end
86
86
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LunaPark
4
- VERSION = '0.13.0'
4
+ VERSION = '0.13.2'
5
5
  end
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.0
4
+ version: 0.13.2
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-08 00:00:00.000000000 Z
12
+ date: 2023-12-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bugsnag