hanami-model 1.2.0 → 1.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +21 -0
  3. data/LICENSE.md +1 -1
  4. data/README.md +10 -7
  5. data/hanami-model.gemspec +25 -20
  6. data/lib/hanami-model.rb +3 -1
  7. data/lib/hanami/entity.rb +6 -3
  8. data/lib/hanami/entity/schema.rb +10 -7
  9. data/lib/hanami/model.rb +15 -12
  10. data/lib/hanami/model/association.rb +7 -7
  11. data/lib/hanami/model/associations/belongs_to.rb +3 -1
  12. data/lib/hanami/model/associations/dsl.rb +2 -2
  13. data/lib/hanami/model/associations/has_many.rb +10 -8
  14. data/lib/hanami/model/associations/has_one.rb +9 -7
  15. data/lib/hanami/model/associations/many_to_many.rb +9 -11
  16. data/lib/hanami/model/configuration.rb +29 -10
  17. data/lib/hanami/model/configurator.rb +5 -3
  18. data/lib/hanami/model/entity_name.rb +4 -2
  19. data/lib/hanami/model/error.rb +18 -7
  20. data/lib/hanami/model/mapped_relation.rb +4 -2
  21. data/lib/hanami/model/mapping.rb +3 -1
  22. data/lib/hanami/model/migration.rb +2 -0
  23. data/lib/hanami/model/migrator.rb +7 -5
  24. data/lib/hanami/model/migrator/adapter.rb +14 -12
  25. data/lib/hanami/model/migrator/connection.rb +16 -9
  26. data/lib/hanami/model/migrator/logger.rb +3 -1
  27. data/lib/hanami/model/migrator/mysql_adapter.rb +23 -13
  28. data/lib/hanami/model/migrator/postgres_adapter.rb +31 -31
  29. data/lib/hanami/model/migrator/sqlite_adapter.rb +7 -9
  30. data/lib/hanami/model/plugins.rb +5 -3
  31. data/lib/hanami/model/plugins/mapping.rb +2 -0
  32. data/lib/hanami/model/plugins/schema.rb +2 -0
  33. data/lib/hanami/model/plugins/timestamps.rb +3 -0
  34. data/lib/hanami/model/relation_name.rb +4 -2
  35. data/lib/hanami/model/sql.rb +9 -7
  36. data/lib/hanami/model/sql/console.rb +10 -8
  37. data/lib/hanami/model/sql/consoles/abstract.rb +3 -1
  38. data/lib/hanami/model/sql/consoles/mysql.rb +4 -2
  39. data/lib/hanami/model/sql/consoles/postgresql.rb +10 -8
  40. data/lib/hanami/model/sql/consoles/sqlite.rb +6 -4
  41. data/lib/hanami/model/sql/entity/schema.rb +6 -4
  42. data/lib/hanami/model/sql/types.rb +27 -27
  43. data/lib/hanami/model/sql/types/schema/coercions.rb +5 -4
  44. data/lib/hanami/model/types.rb +4 -4
  45. data/lib/hanami/model/version.rb +3 -1
  46. data/lib/hanami/repository.rb +20 -31
  47. metadata +64 -8
@@ -1,5 +1,7 @@
1
- require_relative 'abstract'
2
- require 'shellwords'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "abstract"
4
+ require "shellwords"
3
5
 
4
6
  module Hanami
5
7
  module Model
@@ -12,12 +14,12 @@ module Hanami
12
14
  class Sqlite < Abstract
13
15
  # @since 0.7.0
14
16
  # @api private
15
- COMMAND = 'sqlite3'.freeze
17
+ COMMAND = "sqlite3"
16
18
 
17
19
  # @since 0.7.0
18
20
  # @api private
19
21
  def connection_string
20
- concat(command, ' ', host, database)
22
+ concat(command, " ", host, database)
21
23
  end
22
24
 
23
25
  private
@@ -1,6 +1,8 @@
1
- require 'hanami/entity/schema'
2
- require 'hanami/model/types'
3
- require 'hanami/model/association'
1
+ # frozen_string_literal: true
2
+
3
+ require "hanami/entity/schema"
4
+ require "hanami/model/types"
5
+ require "hanami/model/association"
4
6
 
5
7
  module Hanami
6
8
  module Model
@@ -52,7 +54,7 @@ module Hanami
52
54
 
53
55
  # @since 1.0.1
54
56
  # @api private
55
- alias [] call
57
+ alias_method :[], :call
56
58
 
57
59
  # Check if the attribute is known
58
60
  #
@@ -1,5 +1,7 @@
1
- require 'hanami/model/types'
2
- require 'rom/types'
1
+ # frozen_string_literal: true
2
+
3
+ require "hanami/model/types"
4
+ require "rom/types"
3
5
 
4
6
  module Hanami
5
7
  module Model
@@ -14,7 +16,7 @@ module Hanami
14
16
  #
15
17
  # @since 0.7.0
16
18
  module Schema
17
- require 'hanami/model/sql/types/schema/coercions'
19
+ require "hanami/model/sql/types/schema/coercions"
18
20
 
19
21
  String = Types::Optional::Coercible::String
20
22
 
@@ -36,26 +38,26 @@ module Hanami
36
38
  # @since 0.7.0
37
39
  # @api private
38
40
  MAPPING = {
39
- Types::String.pristine => Schema::String,
40
- Types::Int.pristine => Schema::Int,
41
- Types::Float.pristine => Schema::Float,
42
- Types::Decimal.pristine => Schema::Decimal,
43
- Types::Bool.pristine => Schema::Bool,
44
- Types::Date.pristine => Schema::Date,
45
- Types::DateTime.pristine => Schema::DateTime,
46
- Types::Time.pristine => Schema::Time,
47
- Types::Array.pristine => Schema::Array,
48
- Types::Hash.pristine => Schema::Hash,
49
- Types::String.optional.pristine => Schema::String,
50
- Types::Int.optional.pristine => Schema::Int,
51
- Types::Float.optional.pristine => Schema::Float,
52
- Types::Decimal.optional.pristine => Schema::Decimal,
53
- Types::Bool.optional.pristine => Schema::Bool,
54
- Types::Date.optional.pristine => Schema::Date,
41
+ Types::String.pristine => Schema::String,
42
+ Types::Int.pristine => Schema::Int,
43
+ Types::Float.pristine => Schema::Float,
44
+ Types::Decimal.pristine => Schema::Decimal,
45
+ Types::Bool.pristine => Schema::Bool,
46
+ Types::Date.pristine => Schema::Date,
47
+ Types::DateTime.pristine => Schema::DateTime,
48
+ Types::Time.pristine => Schema::Time,
49
+ Types::Array.pristine => Schema::Array,
50
+ Types::Hash.pristine => Schema::Hash,
51
+ Types::String.optional.pristine => Schema::String,
52
+ Types::Int.optional.pristine => Schema::Int,
53
+ Types::Float.optional.pristine => Schema::Float,
54
+ Types::Decimal.optional.pristine => Schema::Decimal,
55
+ Types::Bool.optional.pristine => Schema::Bool,
56
+ Types::Date.optional.pristine => Schema::Date,
55
57
  Types::DateTime.optional.pristine => Schema::DateTime,
56
- Types::Time.optional.pristine => Schema::Time,
57
- Types::Array.optional.pristine => Schema::Array,
58
- Types::Hash.optional.pristine => Schema::Hash
58
+ Types::Time.optional.pristine => Schema::Time,
59
+ Types::Array.optional.pristine => Schema::Array,
60
+ Types::Hash.optional.pristine => Schema::Hash
59
61
  }.freeze
60
62
 
61
63
  # Convert given type into coercible
@@ -86,17 +88,15 @@ module Hanami
86
88
  # @api private
87
89
  def self.pg_json_pristines
88
90
  @pg_json_pristines ||= ::Hash.new do |hash, type|
89
- hash[type] = if defined?(ROM::SQL::Types::PG)
90
- ROM::SQL::Types::PG.const_get(type).pristine
91
- end
91
+ hash[type] = (ROM::SQL::Types::PG.const_get(type).pristine if defined?(ROM::SQL::Types::PG))
92
92
  end
93
93
  end
94
94
 
95
95
  # @since 1.0.2
96
96
  # @api private
97
97
  def self.pg_json?(pristine)
98
- pristine == pg_json_pristines['JSONB'.freeze] ||
99
- pristine == pg_json_pristines['JSON'.freeze]
98
+ pristine == pg_json_pristines["JSONB"] || # rubocop:disable Style/MultipleComparison
99
+ pristine == pg_json_pristines["JSON"]
100
100
  end
101
101
 
102
102
  private_class_method :pg_json?
@@ -1,5 +1,7 @@
1
- require 'hanami/utils/string'
2
- require 'hanami/utils/hash'
1
+ # frozen_string_literal: true
2
+
3
+ require "hanami/utils/string"
4
+ require "hanami/utils/hash"
3
5
 
4
6
  module Hanami
5
7
  module Model
@@ -12,7 +14,6 @@ module Hanami
12
14
  # @api private
13
15
  #
14
16
  # rubocop:disable Metrics/ModuleLength
15
- # rubocop:disable Metrics/MethodLength
16
17
  module Coercions
17
18
  # Coerces given argument into Integer
18
19
  #
@@ -215,7 +216,7 @@ module Hanami
215
216
  end
216
217
  end
217
218
  end
218
- # rubocop:enable Metrics/MethodLength
219
+
219
220
  # rubocop:enable Metrics/ModuleLength
220
221
  end
221
222
  end
@@ -1,4 +1,6 @@
1
- require 'rom/types'
1
+ # frozen_string_literal: true
2
+
3
+ require "rom/types"
2
4
 
3
5
  module Hanami
4
6
  module Model
@@ -17,7 +19,6 @@ module Hanami
17
19
  # Class level interface
18
20
  #
19
21
  # @since 0.7.0
20
- # rubocop:disable Naming/MethodName
21
22
  module ClassMethods
22
23
  # Define an entity of the given type
23
24
  #
@@ -77,7 +78,6 @@ module Hanami
77
78
  Types::Array.member(type)
78
79
  end
79
80
  end
80
- # rubocop:enable Naming/MethodName
81
81
 
82
82
  # Types for schema definitions
83
83
  #
@@ -101,7 +101,7 @@ module Hanami
101
101
  def call(value)
102
102
  return if value.nil?
103
103
 
104
- if valid?(value) # rubocop:disable Style/GuardClause
104
+ if valid?(value)
105
105
  coerce(value)
106
106
  else
107
107
  raise TypeError.new("#{value.inspect} must be coercible into #{object}")
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Hanami
2
4
  module Model
3
5
  # Defines the version
4
6
  #
5
7
  # @since 0.1.0
6
- VERSION = '1.2.0'.freeze
8
+ VERSION = "1.3.3"
7
9
  end
8
10
  end
@@ -1,12 +1,14 @@
1
- require 'rom-repository'
2
- require 'hanami/model/entity_name'
3
- require 'hanami/model/relation_name'
4
- require 'hanami/model/mapped_relation'
5
- require 'hanami/model/associations/dsl'
6
- require 'hanami/model/association'
7
- require 'hanami/utils/class'
8
- require 'hanami/utils/class_attribute'
9
- require 'hanami/utils/io'
1
+ # frozen_string_literal: true
2
+
3
+ require "rom-repository"
4
+ require "hanami/model/entity_name"
5
+ require "hanami/model/relation_name"
6
+ require "hanami/model/mapped_relation"
7
+ require "hanami/model/associations/dsl"
8
+ require "hanami/model/association"
9
+ require "hanami/utils/class"
10
+ require "hanami/utils/class_attribute"
11
+ require "hanami/utils/io"
10
12
 
11
13
  module Hanami
12
14
  # Mediates between the entities and the persistence layer, by offering an API
@@ -107,7 +109,7 @@ module Hanami
107
109
  # @see Hanami::Entity
108
110
  # @see http://martinfowler.com/eaaCatalog/repository.html
109
111
  # @see http://en.wikipedia.org/wiki/Dependency_inversion_principle
110
- class Repository < ROM::Repository::Root # rubocop:disable Metrics/ClassLength
112
+ class Repository < ROM::Repository::Root
111
113
  # Plugins for database commands
112
114
  #
113
115
  # @since 0.7.0
@@ -155,7 +157,6 @@ module Hanami
155
157
  def command(*args, **opts, &block)
156
158
  opts[:use] = COMMAND_PLUGINS | Array(opts[:use])
157
159
  opts[:mapper] = opts.fetch(:mapper, Model::MappedRelation.mapper_name)
158
-
159
160
  super(*args, **opts, &block)
160
161
  end
161
162
 
@@ -167,8 +168,6 @@ module Hanami
167
168
  # @since 0.7.0
168
169
  # @api private
169
170
  #
170
- # rubocop:disable Metrics/MethodLength
171
- # rubocop:disable Metrics/AbcSize
172
171
  def self.define_relation
173
172
  a = @associations
174
173
  s = @schema
@@ -191,8 +190,6 @@ module Hanami
191
190
  end
192
191
  }, __FILE__, __LINE__ - 4
193
192
  end
194
- # rubocop:enable Metrics/AbcSize
195
- # rubocop:enable Metrics/MethodLength
196
193
 
197
194
  # Defines the mapping between a database table and an entity.
198
195
  #
@@ -201,8 +198,6 @@ module Hanami
201
198
  # @since 0.7.0
202
199
  # @api private
203
200
  #
204
- # rubocop:disable Metrics/MethodLength
205
- # rubocop:disable Metrics/AbcSize
206
201
  def self.define_mapping
207
202
  self.entity = Utils::Class.load!(entity_name)
208
203
  e = entity
@@ -219,8 +214,6 @@ module Hanami
219
214
  configuration.define_mappings(root, &blk)
220
215
  configuration.register_entity(relation, entity_name.underscore, e)
221
216
  end
222
- # rubocop:enable Metrics/AbcSize
223
- # rubocop:enable Metrics/MethodLength
224
217
 
225
218
  # It defines associations, by adding relations to the repository
226
219
  #
@@ -302,8 +295,6 @@ module Hanami
302
295
  # @since 0.7.0
303
296
  # @api private
304
297
  #
305
- # rubocop:disable Metrics/MethodLength
306
- # rubocop:disable Metrics/AbcSize
307
298
  def self.inherited(klass)
308
299
  klass.class_eval do
309
300
  include Utils::ClassAttribute
@@ -332,8 +323,6 @@ module Hanami
332
323
 
333
324
  Hanami::Model.repositories << klass
334
325
  end
335
- # rubocop:enable Metrics/AbcSize
336
- # rubocop:enable Metrics/MethodLength
337
326
 
338
327
  # Extend commands from ROM::Repository with error management
339
328
  #
@@ -358,8 +347,8 @@ module Hanami
358
347
  # entity.id # => nil - It doesn't mutate original entity
359
348
  def create(*args)
360
349
  super
361
- rescue => e
362
- raise Hanami::Model::Error.for(e)
350
+ rescue => exception
351
+ raise Hanami::Model::Error.for(exception)
363
352
  end
364
353
 
365
354
  # Update a record
@@ -387,8 +376,8 @@ module Hanami
387
376
  # entity.id # => nil - It doesn't mutate original entity
388
377
  def update(*args)
389
378
  super
390
- rescue => e
391
- raise Hanami::Model::Error.for(e)
379
+ rescue => exception
380
+ raise Hanami::Model::Error.for(exception)
392
381
  end
393
382
 
394
383
  # Delete a record
@@ -406,8 +395,8 @@ module Hanami
406
395
  # user = repository.delete(user.id)
407
396
  def delete(*args)
408
397
  super
409
- rescue => e
410
- raise Hanami::Model::Error.for(e)
398
+ rescue => exception
399
+ raise Hanami::Model::Error.for(exception)
411
400
  end
412
401
  end
413
402
 
@@ -436,8 +425,8 @@ module Hanami
436
425
  # user = repository.find(user.id)
437
426
  def find(id)
438
427
  root.by_pk(id).as(:entity).one
439
- rescue => e
440
- raise Hanami::Model::Error.for(e)
428
+ rescue => exception
429
+ raise Hanami::Model::Error.for(exception)
441
430
  end
442
431
 
443
432
  # Return all the records for the relation
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hanami-model
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luca Guidi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-11 00:00:00.000000000 Z
11
+ date: 2021-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hanami-utils
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.2'
19
+ version: '1.3'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.2'
26
+ version: '1.3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rom
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -92,6 +92,26 @@ dependencies:
92
92
  - - "~>"
93
93
  - !ruby/object:Gem::Version
94
94
  version: 0.11.0
95
+ - !ruby/object:Gem::Dependency
96
+ name: dry-logic
97
+ requirement: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - "~>"
100
+ - !ruby/object:Gem::Version
101
+ version: 0.4.2
102
+ - - "<"
103
+ - !ruby/object:Gem::Version
104
+ version: '0.5'
105
+ type: :runtime
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - "~>"
110
+ - !ruby/object:Gem::Version
111
+ version: 0.4.2
112
+ - - "<"
113
+ - !ruby/object:Gem::Version
114
+ version: '0.5'
95
115
  - !ruby/object:Gem::Dependency
96
116
  name: concurrent-ruby
97
117
  requirement: !ruby/object:Gem::Requirement
@@ -106,20 +126,40 @@ dependencies:
106
126
  - - "~>"
107
127
  - !ruby/object:Gem::Version
108
128
  version: '1.0'
129
+ - !ruby/object:Gem::Dependency
130
+ name: bigdecimal
131
+ requirement: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - "~>"
134
+ - !ruby/object:Gem::Version
135
+ version: '1.4'
136
+ type: :runtime
137
+ prerelease: false
138
+ version_requirements: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - "~>"
141
+ - !ruby/object:Gem::Version
142
+ version: '1.4'
109
143
  - !ruby/object:Gem::Dependency
110
144
  name: bundler
111
145
  requirement: !ruby/object:Gem::Requirement
112
146
  requirements:
113
147
  - - ">="
114
148
  - !ruby/object:Gem::Version
115
- version: '0'
149
+ version: '1.6'
150
+ - - "<"
151
+ - !ruby/object:Gem::Version
152
+ version: '3'
116
153
  type: :development
117
154
  prerelease: false
118
155
  version_requirements: !ruby/object:Gem::Requirement
119
156
  requirements:
120
157
  - - ">="
121
158
  - !ruby/object:Gem::Version
122
- version: '0'
159
+ version: '1.6'
160
+ - - "<"
161
+ - !ruby/object:Gem::Version
162
+ version: '3'
123
163
  - !ruby/object:Gem::Dependency
124
164
  name: rake
125
165
  requirement: !ruby/object:Gem::Requirement
@@ -148,6 +188,20 @@ dependencies:
148
188
  - - "~>"
149
189
  - !ruby/object:Gem::Version
150
190
  version: '3.7'
191
+ - !ruby/object:Gem::Dependency
192
+ name: rubocop
193
+ requirement: !ruby/object:Gem::Requirement
194
+ requirements:
195
+ - - '='
196
+ - !ruby/object:Gem::Version
197
+ version: '0.81'
198
+ type: :development
199
+ prerelease: false
200
+ version_requirements: !ruby/object:Gem::Requirement
201
+ requirements:
202
+ - - '='
203
+ - !ruby/object:Gem::Version
204
+ version: '0.81'
151
205
  description: A persistence framework with entities and repositories
152
206
  email:
153
207
  - me@lucaguidi.com
@@ -213,14 +267,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
213
267
  - - ">="
214
268
  - !ruby/object:Gem::Version
215
269
  version: 2.3.0
270
+ - - "<"
271
+ - !ruby/object:Gem::Version
272
+ version: '3'
216
273
  required_rubygems_version: !ruby/object:Gem::Requirement
217
274
  requirements:
218
275
  - - ">="
219
276
  - !ruby/object:Gem::Version
220
277
  version: '0'
221
278
  requirements: []
222
- rubyforge_project:
223
- rubygems_version: 2.7.6
279
+ rubygems_version: 3.2.2
224
280
  signing_key:
225
281
  specification_version: 4
226
282
  summary: A persistence layer for Hanami