hanami-model 1.0.0.beta2 → 1.0.0.beta3
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 +4 -4
- data/CHANGELOG.md +4 -0
- data/LICENSE.md +1 -1
- data/lib/hanami/entity/schema.rb +23 -7
- data/lib/hanami/model.rb +28 -0
- data/lib/hanami/model/entity_name.rb +2 -0
- data/lib/hanami/model/error.rb +12 -0
- data/lib/hanami/model/mapping.rb +10 -0
- data/lib/hanami/model/migrator/adapter.rb +2 -0
- data/lib/hanami/model/migrator/connection.rb +1 -0
- data/lib/hanami/model/sql/console.rb +2 -0
- data/lib/hanami/model/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 814a3f29d87d2da6aebb6ba4087d10a90e9503af
|
4
|
+
data.tar.gz: 507495e34d73b7165624f363f87cbe9da59ee61c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f6c588f340066f3225ec6f5d6fe27bcdc0b3f6ee1dcdd888181e69dfc43db927ace14c59a573d8e8c1b7015d5246023be889a53dc864e2edd6c3699e2eaff58
|
7
|
+
data.tar.gz: 06274bd95fbb3f72dac7f513236b779e7c119fc3dbd9eae0bcb031af0b34ae1704aee850759207b17ed51297354ec6f5851dd64cbf3aeb41f931183ca1374a1f
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
# Hanami::Model
|
2
2
|
A persistence layer for Hanami
|
3
3
|
|
4
|
+
## v1.0.0.beta3 - 2017-03-17
|
5
|
+
### Added
|
6
|
+
- [Luca Guidi] Introduced `Hanami::Model.disconnect` to disconnect all the active database connections
|
7
|
+
|
4
8
|
## v1.0.0.beta2 - 2017-03-02
|
5
9
|
### Added
|
6
10
|
- [Semyon Pupkov] Allow to define Postgres connection URL as `"postgresql:///mydb?host=localhost&port=6433&user=postgres&password=testpasswd"`
|
data/LICENSE.md
CHANGED
data/lib/hanami/entity/schema.rb
CHANGED
@@ -11,8 +11,7 @@ module Hanami
|
|
11
11
|
# @example SQL Automatic Setup
|
12
12
|
# require 'hanami/model'
|
13
13
|
#
|
14
|
-
# class Account
|
15
|
-
# include Hanami::Entity
|
14
|
+
# class Account < Hanami::Entity
|
16
15
|
# end
|
17
16
|
#
|
18
17
|
# account = Account.new(name: "Acme Inc.")
|
@@ -24,9 +23,7 @@ module Hanami
|
|
24
23
|
# @example Non-SQL Manual Setup
|
25
24
|
# require 'hanami/model'
|
26
25
|
#
|
27
|
-
# class Account
|
28
|
-
# include Hanami::Entity
|
29
|
-
#
|
26
|
+
# class Account < Hanami::Entity
|
30
27
|
# attributes do
|
31
28
|
# attribute :id, Types::Int
|
32
29
|
# attribute :name, Types::String
|
@@ -46,8 +43,7 @@ module Hanami
|
|
46
43
|
# @example Schemaless Entity
|
47
44
|
# require 'hanami/model'
|
48
45
|
#
|
49
|
-
# class Account
|
50
|
-
# include Hanami::Entity
|
46
|
+
# class Account < Hanami::Entity
|
51
47
|
# end
|
52
48
|
#
|
53
49
|
# account = Account.new(name: "Acme Inc.")
|
@@ -117,6 +113,26 @@ module Hanami
|
|
117
113
|
# @param type [Dry::Types::Definition] the attribute type
|
118
114
|
#
|
119
115
|
# @since 0.7.0
|
116
|
+
#
|
117
|
+
# @example
|
118
|
+
# require 'hanami/model'
|
119
|
+
#
|
120
|
+
# class Account < Hanami::Entity
|
121
|
+
# attributes do
|
122
|
+
# attribute :id, Types::Int
|
123
|
+
# attribute :name, Types::String
|
124
|
+
# attribute :codes, Types::Array(Types::Int)
|
125
|
+
# attribute :users, Types::Array(User)
|
126
|
+
# attribute :email, Types::String.constrained(format: /@/)
|
127
|
+
# attribute :created_at, Types::DateTime
|
128
|
+
# end
|
129
|
+
# end
|
130
|
+
#
|
131
|
+
# account = Account.new(name: "Acme Inc.")
|
132
|
+
# account.name # => "Acme Inc."
|
133
|
+
#
|
134
|
+
# account = Account.new(foo: "bar")
|
135
|
+
# account.foo # => NoMethodError
|
120
136
|
def attribute(name, type)
|
121
137
|
@attributes[name] = type
|
122
138
|
end
|
data/lib/hanami/model.rb
CHANGED
@@ -3,6 +3,9 @@ require 'concurrent'
|
|
3
3
|
require 'hanami/entity'
|
4
4
|
require 'hanami/repository'
|
5
5
|
|
6
|
+
# Hanami
|
7
|
+
#
|
8
|
+
# @since 0.1.0
|
6
9
|
module Hanami
|
7
10
|
# Hanami persistence
|
8
11
|
#
|
@@ -76,5 +79,30 @@ module Hanami
|
|
76
79
|
@container = configuration.load!(repositories, &blk)
|
77
80
|
@loaded = true
|
78
81
|
end
|
82
|
+
|
83
|
+
# Disconnect from the database
|
84
|
+
#
|
85
|
+
# This is useful for reboot applications in production and to ensure that
|
86
|
+
# the framework prunes stale connections.
|
87
|
+
#
|
88
|
+
# @since x.x.x
|
89
|
+
#
|
90
|
+
# @example With Full Stack Hanami Project
|
91
|
+
# # config/puma.rb
|
92
|
+
# # ...
|
93
|
+
# on_worker_boot do
|
94
|
+
# Hanami.boot
|
95
|
+
# end
|
96
|
+
#
|
97
|
+
# @example With Standalone Hanami::Model
|
98
|
+
# # config/puma.rb
|
99
|
+
# # ...
|
100
|
+
# on_worker_boot do
|
101
|
+
# Hanami::Model.disconnect
|
102
|
+
# Hanami::Model.load!
|
103
|
+
# end
|
104
|
+
def self.disconnect
|
105
|
+
configuration.connection && configuration.connection.disconnect
|
106
|
+
end
|
79
107
|
end
|
80
108
|
end
|
data/lib/hanami/model/error.rb
CHANGED
@@ -39,6 +39,8 @@ module Hanami
|
|
39
39
|
#
|
40
40
|
# @since 0.5.0
|
41
41
|
class InvalidCommandError < Error
|
42
|
+
# @since 0.5.0
|
43
|
+
# @api private
|
42
44
|
def initialize(message = 'Invalid command')
|
43
45
|
super
|
44
46
|
end
|
@@ -48,6 +50,8 @@ module Hanami
|
|
48
50
|
#
|
49
51
|
# @since 0.7.0
|
50
52
|
class ConstraintViolationError < Error
|
53
|
+
# @since 0.7.0
|
54
|
+
# @api private
|
51
55
|
def initialize(message = 'Constraint has been violated')
|
52
56
|
super
|
53
57
|
end
|
@@ -57,6 +61,8 @@ module Hanami
|
|
57
61
|
#
|
58
62
|
# @since 0.6.1
|
59
63
|
class UniqueConstraintViolationError < Error
|
64
|
+
# @since 0.6.1
|
65
|
+
# @api private
|
60
66
|
def initialize(message = 'Unique constraint has been violated')
|
61
67
|
super
|
62
68
|
end
|
@@ -66,6 +72,8 @@ module Hanami
|
|
66
72
|
#
|
67
73
|
# @since 0.6.1
|
68
74
|
class ForeignKeyConstraintViolationError < Error
|
75
|
+
# @since 0.6.1
|
76
|
+
# @api private
|
69
77
|
def initialize(message = 'Foreign key constraint has been violated')
|
70
78
|
super
|
71
79
|
end
|
@@ -75,6 +83,8 @@ module Hanami
|
|
75
83
|
#
|
76
84
|
# @since 0.6.1
|
77
85
|
class NotNullConstraintViolationError < Error
|
86
|
+
# @since 0.6.1
|
87
|
+
# @api private
|
78
88
|
def initialize(message = 'NOT NULL constraint has been violated')
|
79
89
|
super
|
80
90
|
end
|
@@ -84,6 +94,8 @@ module Hanami
|
|
84
94
|
#
|
85
95
|
# @since 0.6.1
|
86
96
|
class CheckConstraintViolationError < Error
|
97
|
+
# @since 0.6.1
|
98
|
+
# @api private
|
87
99
|
def initialize(message = 'Check constraint has been violated')
|
88
100
|
super
|
89
101
|
end
|
data/lib/hanami/model/mapping.rb
CHANGED
@@ -5,11 +5,14 @@ module Hanami
|
|
5
5
|
# Mapping
|
6
6
|
#
|
7
7
|
# @since 0.1.0
|
8
|
+
# @api private
|
8
9
|
class Mapping
|
9
10
|
extend Transproc::Registry
|
10
11
|
|
11
12
|
import Transproc::HashTransformations
|
12
13
|
|
14
|
+
# @since 0.1.0
|
15
|
+
# @api private
|
13
16
|
def initialize(&blk)
|
14
17
|
@attributes = {}
|
15
18
|
@r_attributes = {}
|
@@ -17,16 +20,20 @@ module Hanami
|
|
17
20
|
@processor = @attributes.empty? ? ::Hash : t(:rename_keys, @attributes)
|
18
21
|
end
|
19
22
|
|
23
|
+
# @api private
|
20
24
|
def t(name, *args)
|
21
25
|
self.class[name, *args]
|
22
26
|
end
|
23
27
|
|
28
|
+
# @api private
|
24
29
|
def model(entity)
|
25
30
|
end
|
26
31
|
|
32
|
+
# @api private
|
27
33
|
def register_as(name)
|
28
34
|
end
|
29
35
|
|
36
|
+
# @api private
|
30
37
|
def attribute(name, options)
|
31
38
|
from = options.fetch(:from, name)
|
32
39
|
|
@@ -34,14 +41,17 @@ module Hanami
|
|
34
41
|
@r_attributes[from] = name
|
35
42
|
end
|
36
43
|
|
44
|
+
# @api private
|
37
45
|
def process(input)
|
38
46
|
@processor[input]
|
39
47
|
end
|
40
48
|
|
49
|
+
# @api private
|
41
50
|
def reverse?
|
42
51
|
@r_attributes.any?
|
43
52
|
end
|
44
53
|
|
54
|
+
# @api private
|
45
55
|
def translate(attribute)
|
46
56
|
@r_attributes.fetch(attribute)
|
47
57
|
end
|
data/lib/hanami/model/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hanami-model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.
|
4
|
+
version: 1.0.0.beta3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luca Guidi
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2017-03-
|
13
|
+
date: 2017-03-17 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: hanami-utils
|