pakyow-data 1.0.0.rc5 → 1.0.0

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: b0508f7f451c68fe8254c7a468a41a84673f9190405168ede5964e36fc7c6563
4
- data.tar.gz: 6a629f8c9d1b29977efb5184f3c9147241fd5b5b0eb05eb86d2161891854fe47
3
+ metadata.gz: e05427fdd149e88fb48af9182abc15a427dcb8b621c4cb9e362d5df377ab157f
4
+ data.tar.gz: a219ae7c4044104a259adf7e901d51c4655f0e746cf79e1491c477716f72242b
5
5
  SHA512:
6
- metadata.gz: 7dc9e1446b99fea5d84ea4c01fbc764e1005a71c579e9fcddc6cf69f592aee6355d52aa57f8093e9bf894bd40256bfe7b961b3ab4d2142c3d835bb29b647a744
7
- data.tar.gz: e10524efdf8522441aa20df907e8301a85eafb633c55ef4da25e09cb1c4608e103d15750ac0c8d46379812df9de66462d6e4eb679d44dff8913932d7ec369868
6
+ metadata.gz: 44e1ab1da9e2f891255856fefa0821e8547be015dce16beab0823603d631dbdc4d34e55ec091c2e1ee756712956751c6d7ebe9ef36615fb52dfd885acdfb276f
7
+ data.tar.gz: b6e2caffba485db823a392901f88334bd95ef3e7b96e688e81b62e62ada92baa2ac2fedfa2bc51ea40f64e5ef06ac5b02f73e24b7f6e28ec851ef13f39728225
data/CHANGELOG.md CHANGED
@@ -0,0 +1,5 @@
1
+ # UNRELEASED
2
+
3
+ # 1.0
4
+
5
+ * Hello, Web
@@ -0,0 +1,77 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pakyow/support/extension"
4
+
5
+ require "pakyow/data/container"
6
+ require "pakyow/data/lookup"
7
+ require "pakyow/data/subscribers"
8
+
9
+ module Pakyow
10
+ class Application
11
+ module Behavior
12
+ module Data
13
+ module Lookup
14
+ extend Support::Extension
15
+
16
+ # Data container object.
17
+ #
18
+ attr_reader :data
19
+
20
+ apply_extension do
21
+ after "boot", "initialize.data", priority: :high do
22
+ # Validate that each source connection exists.
23
+ #
24
+ state(:source).each do |source|
25
+ Pakyow.connection(source.adapter, source.connection)
26
+ end
27
+
28
+ subscribers = if is_a?(Plugin)
29
+ # Plugins should use the same subscribers object as their parent app.
30
+ #
31
+ parent.data.subscribers
32
+ else
33
+ Pakyow::Data::Subscribers.new(
34
+ self,
35
+ Pakyow.config.data.subscriptions.adapter,
36
+ Pakyow.config.data.subscriptions.adapter_settings
37
+ )
38
+ end
39
+
40
+ containers = Pakyow.data_connections.values.each_with_object([]) { |connections, arr|
41
+ connections.values.each do |connection|
42
+ arr << Pakyow::Data::Container.new(
43
+ connection: connection,
44
+ sources: state(:source).select { |source|
45
+ connection.name == source.connection && connection.type == source.adapter
46
+ },
47
+ objects: state(:object)
48
+ )
49
+ end
50
+ }
51
+
52
+ containers.each do |container|
53
+ container.finalize_associations!(containers - [container])
54
+ end
55
+
56
+ containers.each do |container|
57
+ container.finalize_sources!(containers - [container])
58
+ end
59
+
60
+ @data = Pakyow::Data::Lookup.new(
61
+ app: self,
62
+ containers: containers,
63
+ subscribers: subscribers
64
+ )
65
+ end
66
+
67
+ on "shutdown" do
68
+ if instance_variable_defined?(:@data)
69
+ @data.subscribers.shutdown
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pakyow/support/extension"
4
+ require "pakyow/support/serializer"
5
+
6
+ module Pakyow
7
+ class Application
8
+ module Behavior
9
+ module Data
10
+ # Persists in-memory subscribers across restarts.
11
+ #
12
+ module Serialization
13
+ extend Support::Extension
14
+
15
+ apply_extension do
16
+ on "shutdown", priority: :high do
17
+ if Pakyow.config.data.subscriptions.adapter == :memory && data
18
+ subscriber_serializer.serialize
19
+ end
20
+ end
21
+
22
+ after "boot" do
23
+ if Pakyow.config.data.subscriptions.adapter == :memory && data
24
+ subscriber_serializer.deserialize
25
+ end
26
+ end
27
+ end
28
+
29
+ private def subscriber_serializer
30
+ Support::Serializer.new(
31
+ data.subscribers.adapter,
32
+ name: "#{config.name}-subscribers",
33
+ path: File.join(
34
+ Pakyow.config.root, "tmp", "state"
35
+ ),
36
+ logger: Pakyow.logger
37
+ )
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -3,9 +3,9 @@
3
3
  require "pakyow/support/extension"
4
4
 
5
5
  module Pakyow
6
- module Data
7
- module Behavior
8
- module Config
6
+ class Application
7
+ module Config
8
+ module Data
9
9
  extend Support::Extension
10
10
 
11
11
  apply_extension do
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pakyow
4
+ class Application
5
+ module Helpers
6
+ module Data
7
+ def data
8
+ @connection.app.data
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -3,7 +3,7 @@
3
3
  require "pakyow/support/extension"
4
4
 
5
5
  module Pakyow
6
- module Environment
6
+ module Behavior
7
7
  module Data
8
8
  module AutoMigrate
9
9
  extend Support::Extension
@@ -5,7 +5,7 @@ require "pakyow/support/extension"
5
5
  require "pakyow/data/connection"
6
6
 
7
7
  module Pakyow
8
- module Environment
8
+ module Behavior
9
9
  module Data
10
10
  module Connections
11
11
  extend Support::Extension
@@ -3,7 +3,7 @@
3
3
  require "pakyow/support/extension"
4
4
 
5
5
  module Pakyow
6
- module Environment
6
+ module Behavior
7
7
  module Data
8
8
  # Configures an in-memory sqlite database.
9
9
  #
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pakyow/support/extension"
4
+
5
+ module Pakyow
6
+ module Config
7
+ module Data
8
+ extend Support::Extension
9
+
10
+ apply_extension do
11
+ on "configure" do
12
+ # We have to define these in a before configure hook since new types could be added.
13
+ #
14
+ Pakyow.config.data.connections.instance_eval do
15
+ Pakyow::Data::Connection.adapter_types.each do |type|
16
+ setting type, {}
17
+ end
18
+ end
19
+ end
20
+
21
+ configurable :data do
22
+ setting :default_adapter, :sql
23
+ setting :default_connection, :default
24
+
25
+ setting :silent, true
26
+ setting :auto_migrate, true
27
+ setting :auto_migrate_always, [:memory]
28
+ setting :migration_path, "./database/migrations"
29
+
30
+ defaults :production do
31
+ setting :auto_migrate, false
32
+ end
33
+
34
+ configurable :subscriptions do
35
+ setting :adapter, :memory
36
+ setting :adapter_settings, {}
37
+
38
+ defaults :production do
39
+ setting :adapter, :redis
40
+ setting :adapter_settings do
41
+ Pakyow.config.redis.to_h
42
+ end
43
+ end
44
+ end
45
+
46
+ configurable :connections do
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
data/lib/pakyow/data.rb CHANGED
@@ -10,18 +10,18 @@ Pakyow::Data::Connection.register_adapter :sql
10
10
  require "pakyow/data/errors"
11
11
  require "pakyow/data/framework"
12
12
 
13
- require "pakyow/environment/data/auto_migrate"
14
- require "pakyow/environment/data/config"
15
- require "pakyow/environment/data/connections"
16
- require "pakyow/environment/data/memory_db"
13
+ require "pakyow/behavior/data/auto_migrate"
14
+ require "pakyow/behavior/data/connections"
15
+ require "pakyow/behavior/data/memory_db"
16
+ require "pakyow/config/data"
17
17
 
18
- require "pakyow/validations/unique"
18
+ require "pakyow/validations/data/unique"
19
19
 
20
20
  module Pakyow
21
- config.tasks.paths << File.expand_path("../data/tasks", __FILE__)
21
+ config.tasks.paths << File.expand_path("../tasks", __FILE__)
22
22
 
23
- include Environment::Data::AutoMigrate
24
- include Environment::Data::Config
25
- include Environment::Data::Connections
26
- include Environment::Data::MemoryDB
23
+ include Behavior::Data::AutoMigrate
24
+ include Behavior::Data::Connections
25
+ include Behavior::Data::MemoryDB
26
+ include Config::Data
27
27
  end
@@ -2,12 +2,12 @@
2
2
 
3
3
  require "pakyow/framework"
4
4
 
5
- require "pakyow/data/object"
6
- require "pakyow/data/helpers"
5
+ require "pakyow/application/config/data"
6
+ require "pakyow/application/behavior/data/lookup"
7
+ require "pakyow/application/behavior/data/serialization"
8
+ require "pakyow/application/helpers/data"
7
9
 
8
- require "pakyow/data/behavior/config"
9
- require "pakyow/data/behavior/lookup"
10
- require "pakyow/data/behavior/serialization"
10
+ require "pakyow/data/object"
11
11
 
12
12
  require "pakyow/data/sources/relational"
13
13
 
@@ -30,11 +30,11 @@ module Pakyow
30
30
  #
31
31
  aspect :objects
32
32
 
33
- register_helper :active, Helpers
33
+ register_helper :active, Pakyow::Application::Helpers::Data
34
34
 
35
- include Behavior::Config
36
- include Behavior::Lookup
37
- include Behavior::Serialization
35
+ include Application::Config::Data
36
+ include Application::Behavior::Data::Lookup
37
+ include Application::Behavior::Data::Serialization
38
38
  end
39
39
  end
40
40
  end
@@ -44,15 +44,13 @@ module Pakyow
44
44
  end
45
45
 
46
46
  def register_subscriptions(subscriptions, subscriber: nil, &block)
47
- @executor << Proc.new {
48
- subscriptions.each do |subscription|
49
- subscription[:version] = @app.config.data.subscriptions.version
50
- end
47
+ subscriptions.each do |subscription|
48
+ subscription[:version] = @app.config.data.subscriptions.version
49
+ end
51
50
 
52
- @adapter.register_subscriptions(subscriptions, subscriber: subscriber).tap do |ids|
53
- yield ids if block_given?
54
- end
55
- }
51
+ @adapter.register_subscriptions(subscriptions, subscriber: subscriber).tap do |ids|
52
+ yield ids if block_given?
53
+ end
56
54
  end
57
55
 
58
56
  def did_mutate(source_name, changed_values = nil, result_source = nil)
@@ -138,9 +138,15 @@ module Pakyow
138
138
  def cleanup
139
139
  @redis.with do |redis|
140
140
  redis.scan_each(match: key_subscription_ids_by_source("*")) do |key|
141
- Pakyow.logger.debug "[Pakyow::Data::Subscribers::Adapters::Redis] Cleaning up expired subscriptions for #{key}"
141
+ Pakyow.logger.internal {
142
+ "[Pakyow::Data::Subscribers::Adapters::Redis] Cleaning up expired subscriptions for #{key}"
143
+ }
144
+
142
145
  removed_count = redis.zremrangebyscore(key, 0, Time.now.to_i)
143
- Pakyow.logger.debug "[Pakyow::Data::Subscribers::Adapters::Redis] Removed #{removed_count} members for #{key}"
146
+
147
+ Pakyow.logger.internal {
148
+ "[Pakyow::Data::Subscribers::Adapters::Redis] Removed #{removed_count} members for #{key}"
149
+ }
144
150
  end
145
151
  end
146
152
  end
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pakyow/support/cli/style"
4
+ require "pakyow/support/dependencies"
5
+
6
+ desc "Show defined sources for an app"
7
+ namespace :info do
8
+ task :sources, [:app] do |_, args|
9
+ sources = args[:app].state(:source).sort_by { |source|
10
+ source.plural_name
11
+ }
12
+
13
+ source_names = sources.map { |source|
14
+ source.plural_name
15
+ }
16
+
17
+ source_locations = sources.map { |source|
18
+ source_location = source.__source_location.to_a.join(":")
19
+
20
+ source_location = if source_location.empty?
21
+ "unknown"
22
+ else
23
+ Pakyow::Support::Dependencies.library_name(source_location) ||
24
+ Pakyow::Support::Dependencies.strip_path_prefix(source_location)
25
+ end
26
+
27
+ source_location = if source_location.start_with?("pakyow-")
28
+ Pakyow::Support::CLI.style.blue(
29
+ "pakyow/#{source_location.split("pakyow-", 2)[1]}"
30
+ )
31
+ elsif source_location == "unknown"
32
+ Pakyow::Support::CLI.style.italic(source_location)
33
+ else
34
+ source_location
35
+ end
36
+ }
37
+
38
+ sources.each_with_index do |source, i|
39
+ puts Pakyow::Support::CLI.style.bold(source_names[i].inspect) + " #{source_locations[i]}"
40
+
41
+ source.associations.each do |association_type, associations|
42
+ associations.each do |association|
43
+ puts " #{association_type} #{association.name.inspect}"
44
+ end
45
+ end
46
+
47
+ if source.attributes.any? && source.associations.values.flatten.any?
48
+ puts
49
+ end
50
+
51
+ if source.attributes.any?
52
+ attributes = source.attributes.sort_by { |attribute_name, _|
53
+ attribute_name
54
+ }
55
+
56
+ attributes.each do |attribute_name, attribute_type|
57
+ puts " attribute #{attribute_name.inspect}, #{attribute_type.meta[:mapping].inspect}"
58
+ end
59
+ end
60
+
61
+ puts
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pakyow/validator"
4
+
5
+ module Pakyow
6
+ module Validations
7
+ module Data
8
+ # Validates that the value is unique within its data source.
9
+ #
10
+ module Unique
11
+ def self.message(**)
12
+ "must be unique"
13
+ end
14
+
15
+ def self.valid?(value, source:, **options)
16
+ query = options[:context].app.data.public_send(source).public_send(:"by_#{options[:key]}", value)
17
+
18
+ if updating = options[:updating]
19
+ if updating.is_a?(Pakyow::Data::Result)
20
+ query.count == 0 || query.any? { |result|
21
+ result[updating.__proxy.source.class.primary_key_field] == updating[updating.__proxy.source.class.primary_key_field]
22
+ }
23
+ else
24
+ raise ArgumentError, "Expected `#{updating.class}' to be a `Pakyow::Data::Result'"
25
+ end
26
+ else
27
+ query.count == 0
28
+ end
29
+ end
30
+ end
31
+
32
+ Validator.register_validation(Unique, :unique)
33
+ end
34
+ end
35
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pakyow-data
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.rc5
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryan Powell
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-07-15 00:00:00.000000000 Z
11
+ date: 2019-07-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pakyow-core
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 1.0.0.rc5
19
+ version: 1.0.0
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.0.0.rc5
26
+ version: 1.0.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: pakyow-support
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 1.0.0.rc5
33
+ version: 1.0.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: 1.0.0.rc5
40
+ version: 1.0.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: concurrent-ruby
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -109,7 +109,7 @@ dependencies:
109
109
  - !ruby/object:Gem::Version
110
110
  version: '5.22'
111
111
  description: Data persistence layer for Pakyow
112
- email: bryan@metabahn.com
112
+ email: bryan@bryanp.org
113
113
  executables: []
114
114
  extensions: []
115
115
  extra_rdoc_files: []
@@ -117,6 +117,14 @@ files:
117
117
  - CHANGELOG.md
118
118
  - LICENSE
119
119
  - README.md
120
+ - lib/pakyow/application/behavior/data/lookup.rb
121
+ - lib/pakyow/application/behavior/data/serialization.rb
122
+ - lib/pakyow/application/config/data.rb
123
+ - lib/pakyow/application/helpers/data.rb
124
+ - lib/pakyow/behavior/data/auto_migrate.rb
125
+ - lib/pakyow/behavior/data/connections.rb
126
+ - lib/pakyow/behavior/data/memory_db.rb
127
+ - lib/pakyow/config/data.rb
120
128
  - lib/pakyow/data.rb
121
129
  - lib/pakyow/data/adapters/base.rb
122
130
  - lib/pakyow/data/adapters/sql.rb
@@ -130,14 +138,10 @@ files:
130
138
  - lib/pakyow/data/adapters/sql/runner.rb
131
139
  - lib/pakyow/data/adapters/sql/source_extension.rb
132
140
  - lib/pakyow/data/adapters/sql/types.rb
133
- - lib/pakyow/data/behavior/config.rb
134
- - lib/pakyow/data/behavior/lookup.rb
135
- - lib/pakyow/data/behavior/serialization.rb
136
141
  - lib/pakyow/data/connection.rb
137
142
  - lib/pakyow/data/container.rb
138
143
  - lib/pakyow/data/errors.rb
139
144
  - lib/pakyow/data/framework.rb
140
- - lib/pakyow/data/helpers.rb
141
145
  - lib/pakyow/data/lookup.rb
142
146
  - lib/pakyow/data/migrator.rb
143
147
  - lib/pakyow/data/object.rb
@@ -161,19 +165,16 @@ files:
161
165
  - lib/pakyow/data/subscribers/adapters/redis/scripts/expire.lua
162
166
  - lib/pakyow/data/subscribers/adapters/redis/scripts/persist.lua
163
167
  - lib/pakyow/data/subscribers/adapters/redis/scripts/register.lua
164
- - lib/pakyow/data/tasks/bootstrap.rake
165
- - lib/pakyow/data/tasks/create.rake
166
- - lib/pakyow/data/tasks/drop.rake
167
- - lib/pakyow/data/tasks/finalize.rake
168
- - lib/pakyow/data/tasks/migrate.rake
169
- - lib/pakyow/data/tasks/reset.rake
170
168
  - lib/pakyow/data/types.rb
171
- - lib/pakyow/environment/data/auto_migrate.rb
172
- - lib/pakyow/environment/data/config.rb
173
- - lib/pakyow/environment/data/connections.rb
174
- - lib/pakyow/environment/data/memory_db.rb
175
- - lib/pakyow/validations/unique.rb
176
- homepage: https://pakyow.org
169
+ - lib/pakyow/tasks/db/bootstrap.rake
170
+ - lib/pakyow/tasks/db/create.rake
171
+ - lib/pakyow/tasks/db/drop.rake
172
+ - lib/pakyow/tasks/db/finalize.rake
173
+ - lib/pakyow/tasks/db/migrate.rake
174
+ - lib/pakyow/tasks/db/reset.rake
175
+ - lib/pakyow/tasks/info/sources.rake
176
+ - lib/pakyow/validations/data/unique.rb
177
+ homepage: https://pakyow.com
177
178
  licenses:
178
179
  - LGPL-3.0
179
180
  metadata: {}
@@ -188,9 +189,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
188
189
  version: 2.5.0
189
190
  required_rubygems_version: !ruby/object:Gem::Requirement
190
191
  requirements:
191
- - - ">"
192
+ - - ">="
192
193
  - !ruby/object:Gem::Version
193
- version: 1.3.1
194
+ version: '0'
194
195
  requirements: []
195
196
  rubygems_version: 3.0.3
196
197
  signing_key:
@@ -1,75 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "pakyow/support/extension"
4
-
5
- require "pakyow/data/container"
6
- require "pakyow/data/lookup"
7
- require "pakyow/data/subscribers"
8
-
9
- module Pakyow
10
- module Data
11
- module Behavior
12
- module Lookup
13
- extend Support::Extension
14
-
15
- # Data container object.
16
- #
17
- attr_reader :data
18
-
19
- apply_extension do
20
- after "boot", "initialize.data", priority: :high do
21
- # Validate that each source connection exists.
22
- #
23
- state(:source).each do |source|
24
- Pakyow.connection(source.adapter, source.connection)
25
- end
26
-
27
- subscribers = if is_a?(Plugin)
28
- # Plugins should use the same subscribers object as their parent app.
29
- #
30
- parent.data.subscribers
31
- else
32
- Subscribers.new(
33
- self,
34
- Pakyow.config.data.subscriptions.adapter,
35
- Pakyow.config.data.subscriptions.adapter_settings
36
- )
37
- end
38
-
39
- containers = Pakyow.data_connections.values.each_with_object([]) { |connections, arr|
40
- connections.values.each do |connection|
41
- arr << Container.new(
42
- connection: connection,
43
- sources: state(:source).select { |source|
44
- connection.name == source.connection && connection.type == source.adapter
45
- },
46
- objects: state(:object)
47
- )
48
- end
49
- }
50
-
51
- containers.each do |container|
52
- container.finalize_associations!(containers - [container])
53
- end
54
-
55
- containers.each do |container|
56
- container.finalize_sources!(containers - [container])
57
- end
58
-
59
- @data = Data::Lookup.new(
60
- app: self,
61
- containers: containers,
62
- subscribers: subscribers
63
- )
64
- end
65
-
66
- on "shutdown" do
67
- if instance_variable_defined?(:@data)
68
- @data.subscribers.shutdown
69
- end
70
- end
71
- end
72
- end
73
- end
74
- end
75
- end
@@ -1,41 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "pakyow/support/extension"
4
- require "pakyow/support/serializer"
5
-
6
- module Pakyow
7
- module Data
8
- module Behavior
9
- # Persists in-memory subscribers across restarts.
10
- #
11
- module Serialization
12
- extend Support::Extension
13
-
14
- apply_extension do
15
- on "shutdown", priority: :high do
16
- if Pakyow.config.data.subscriptions.adapter == :memory && data
17
- subscriber_serializer.serialize
18
- end
19
- end
20
-
21
- after "boot" do
22
- if Pakyow.config.data.subscriptions.adapter == :memory && data
23
- subscriber_serializer.deserialize
24
- end
25
- end
26
- end
27
-
28
- private def subscriber_serializer
29
- Support::Serializer.new(
30
- data.subscribers.adapter,
31
- name: "#{config.name}-subscribers",
32
- path: File.join(
33
- Pakyow.config.root, "tmp", "state"
34
- ),
35
- logger: Pakyow.logger
36
- )
37
- end
38
- end
39
- end
40
- end
41
- end
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Pakyow
4
- module Data
5
- module Helpers
6
- def data
7
- @connection.app.data
8
- end
9
- end
10
- end
11
- end
@@ -1,54 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "pakyow/support/extension"
4
-
5
- module Pakyow
6
- module Environment
7
- module Data
8
- module Config
9
- extend Support::Extension
10
-
11
- apply_extension do
12
- on "configure" do
13
- # We have to define these in a before configure hook since new types could be added.
14
- #
15
- Pakyow.config.data.connections.instance_eval do
16
- Pakyow::Data::Connection.adapter_types.each do |type|
17
- setting type, {}
18
- end
19
- end
20
- end
21
-
22
- configurable :data do
23
- setting :default_adapter, :sql
24
- setting :default_connection, :default
25
-
26
- setting :silent, true
27
- setting :auto_migrate, true
28
- setting :auto_migrate_always, [:memory]
29
- setting :migration_path, "./database/migrations"
30
-
31
- defaults :production do
32
- setting :auto_migrate, false
33
- end
34
-
35
- configurable :subscriptions do
36
- setting :adapter, :memory
37
- setting :adapter_settings, {}
38
-
39
- defaults :production do
40
- setting :adapter, :redis
41
- setting :adapter_settings do
42
- Pakyow.config.redis.to_h
43
- end
44
- end
45
- end
46
-
47
- configurable :connections do
48
- end
49
- end
50
- end
51
- end
52
- end
53
- end
54
- end
@@ -1,33 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "pakyow/validator"
4
-
5
- module Pakyow
6
- module Validations
7
- # Validates that the value is unique within its data source.
8
- #
9
- module Unique
10
- def self.message(**)
11
- "must be unique"
12
- end
13
-
14
- def self.valid?(value, source:, **options)
15
- query = options[:context].app.data.public_send(source).public_send(:"by_#{options[:key]}", value)
16
-
17
- if updating = options[:updating]
18
- if updating.is_a?(Data::Result)
19
- query.count == 0 || query.any? { |result|
20
- result[updating.__proxy.source.class.primary_key_field] == updating[updating.__proxy.source.class.primary_key_field]
21
- }
22
- else
23
- raise ArgumentError, "Expected `#{updating.class}' to be a `Pakyow::Data::Result'"
24
- end
25
- else
26
- query.count == 0
27
- end
28
- end
29
- end
30
-
31
- Validator.register_validation(Unique, :unique)
32
- end
33
- end