activekit 0.2.3.dev4 → 0.2.3.dev5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/active_kit/base/activekiter.rb +0 -4
- data/lib/active_kit/base/middleware.rb +2 -6
- data/lib/active_kit/base.rb +0 -1
- data/lib/active_kit/engine.rb +2 -0
- data/lib/active_kit/version.rb +1 -1
- data/lib/active_kit.rb +0 -1
- metadata +6 -10
- data/lib/active_kit/schedule/middleware.rb +0 -12
- data/lib/active_kit/schedule/schedule.rb +0 -24
- data/lib/active_kit/schedule/scheduleable.rb +0 -97
- data/lib/active_kit/schedule.rb +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b1e6c87aec8ba8d6e11b11d7c95ffb3f47f553a4965705bb49bfec492b6c2991
|
4
|
+
data.tar.gz: cb43e632e5e1e2cf47caf219a48c9359959db8885a8d8c3955e70be4cf01cf9a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 89443ef5fde9805d9033d19e9a2b3f148eaa38128e372a3affd7c8831f0e6988ff92e9227fbc7275cb68e9d0a5db5a38c8fc7dbb49969c157c54604eb3f17404
|
7
|
+
data.tar.gz: b2d3fe63c09a5351d5cfcf6c69192b39ba35242ba4ba279915473d737c5de72807d62b125b7339af0628eb093730b9a51433253b17bd8cc3d452efe0a7ed8695
|
data/README.md
CHANGED
@@ -5,10 +5,6 @@ module ActiveKit
|
|
5
5
|
@current_class = current_class
|
6
6
|
end
|
7
7
|
|
8
|
-
def schedule
|
9
|
-
@schedule ||= ActiveKit::Schedule::Schedule.new(current_class: @current_class)
|
10
|
-
end
|
11
|
-
|
12
8
|
def sequence
|
13
9
|
@sequence ||= ActiveKit::Sequence::Sequence.new(current_class: @current_class)
|
14
10
|
end
|
@@ -9,18 +9,14 @@ module ActiveKit
|
|
9
9
|
def call(env)
|
10
10
|
request = ActionDispatch::Request.new(env)
|
11
11
|
|
12
|
-
|
12
|
+
activekit_run(request) do
|
13
13
|
@app.call(env)
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
17
|
private
|
18
18
|
|
19
|
-
|
20
|
-
# https://guides.rubyonrails.org/autoloading_and_reloading_constants.html#use-case-3-configure-application-classes-for-engines
|
21
|
-
def activekit_runner(request, &blk)
|
22
|
-
"ActiveKit::Schedule::Middleware".constantize.run(request: request)
|
23
|
-
|
19
|
+
def activekit_run(request, &blk)
|
24
20
|
yield
|
25
21
|
end
|
26
22
|
end
|
data/lib/active_kit/base.rb
CHANGED
data/lib/active_kit/engine.rb
CHANGED
data/lib/active_kit/version.rb
CHANGED
data/lib/active_kit.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activekit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.3.
|
4
|
+
version: 0.2.3.dev5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- plainsource
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-11-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -30,9 +30,10 @@ dependencies:
|
|
30
30
|
- - ">="
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: 6.1.3.1
|
33
|
-
description:
|
33
|
+
description: ActiveKit adds useful day-to-day features to ActiveRecord to make the
|
34
|
+
rails developer happy.
|
34
35
|
email:
|
35
|
-
- plainsource@
|
36
|
+
- plainsource@timeboard.org
|
36
37
|
executables: []
|
37
38
|
extensions: []
|
38
39
|
extra_rdoc_files: []
|
@@ -59,10 +60,6 @@ files:
|
|
59
60
|
- lib/active_kit/base/middleware.rb
|
60
61
|
- lib/active_kit/base/relation.rb
|
61
62
|
- lib/active_kit/engine.rb
|
62
|
-
- lib/active_kit/schedule.rb
|
63
|
-
- lib/active_kit/schedule/middleware.rb
|
64
|
-
- lib/active_kit/schedule/schedule.rb
|
65
|
-
- lib/active_kit/schedule/scheduleable.rb
|
66
63
|
- lib/active_kit/sequence.rb
|
67
64
|
- lib/active_kit/sequence/sequence.rb
|
68
65
|
- lib/active_kit/sequence/sequenceable.rb
|
@@ -93,6 +90,5 @@ requirements: []
|
|
93
90
|
rubygems_version: 3.1.2
|
94
91
|
signing_key:
|
95
92
|
specification_version: 4
|
96
|
-
summary:
|
97
|
-
easy.
|
93
|
+
summary: The essential kit for rails ActiveRecord models.
|
98
94
|
test_files: []
|
@@ -1,12 +0,0 @@
|
|
1
|
-
module ActiveKit
|
2
|
-
module Schedule
|
3
|
-
class Middleware
|
4
|
-
def self.run(request:)
|
5
|
-
raise "coming from middleware of activekit schedule."
|
6
|
-
# activekit_attribute = ActiveKit::Attribute.where(value: schedule: timestamp < DateTime.now).order(updated_at: :desc)
|
7
|
-
# json_where = 'value->"$.schedule.attributes.' + attribute_name.to_s + '" = "' + word_for_position + '"'
|
8
|
-
# record_at_position = ActiveKit::Attribute.where(record_type: record.class.name).where(json_where).first&.record
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
module ActiveKit
|
2
|
-
module Schedule
|
3
|
-
class Schedule
|
4
|
-
attr_reader :defined_attributes
|
5
|
-
|
6
|
-
def initialize(current_class:)
|
7
|
-
@current_class = current_class
|
8
|
-
|
9
|
-
@defined_attributes = {}
|
10
|
-
end
|
11
|
-
|
12
|
-
def add(record:, attribute_name:, datetime:, method:)
|
13
|
-
ActiveKit::Base::Ensure.has_one_association_for!(record: record)
|
14
|
-
|
15
|
-
record.activekit_association.schedule[:attributes][attribute_name.to_sym] = nil
|
16
|
-
record.activekit_association.save!
|
17
|
-
end
|
18
|
-
|
19
|
-
def add_attribute(name:, options:)
|
20
|
-
@defined_attributes.store(name, options)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,97 +0,0 @@
|
|
1
|
-
require 'active_support/concern'
|
2
|
-
|
3
|
-
module ActiveKit
|
4
|
-
module Schedule
|
5
|
-
module Scheduleable
|
6
|
-
extend ActiveSupport::Concern
|
7
|
-
|
8
|
-
included do
|
9
|
-
end
|
10
|
-
|
11
|
-
class_methods do
|
12
|
-
# Usage Options
|
13
|
-
# schedule_attribute :name, :run_method, :begin_at, :end_at
|
14
|
-
# schedule_attribute :name, :run_method, :timestamp_method, updater: {}
|
15
|
-
# schedule_attribute :name, :run_method, :timestamp_method, updater: { on: {} }
|
16
|
-
# schedule_attribute :name, :run_method, :timestamp_method, updater: { via: :assoc, on: {} }
|
17
|
-
# schedule_attribute :name, :run_method, :timestamp_method, updater: { via: {}, on: {} }
|
18
|
-
# Note: :on and :via in :updater can accept nested associations.
|
19
|
-
def schedule_attribute(name, run_method, timestamp_method, interval, **options)
|
20
|
-
ActiveKit::Base::Ensure.setup_for!(current_class: self)
|
21
|
-
|
22
|
-
name = name.to_sym
|
23
|
-
options.store(:run_method, run_method&.to_sym)
|
24
|
-
options.store(:timestamp_method, datetime_method&.to_sym)
|
25
|
-
options.deep_symbolize_keys!
|
26
|
-
|
27
|
-
set_activekit_schedule_callbacks(name: name, options: options)
|
28
|
-
activekiter.schedule.add_attribute(name: name, options: options)
|
29
|
-
end
|
30
|
-
|
31
|
-
def set_activekit_schedule_callbacks(name:, options:)
|
32
|
-
run_method = options.dig(:run_method)
|
33
|
-
updater = options.dig(:updater) || {}
|
34
|
-
|
35
|
-
if updater.empty?
|
36
|
-
after_save do
|
37
|
-
self.class.activekiter.schedule.update(record: self, name: name, run_method: run_method)
|
38
|
-
logger.info "ActiveKit | Schedule - Scheduling from #{self.class.name}: Done."
|
39
|
-
end
|
40
|
-
else
|
41
|
-
raise ":updater should be a hash while setting sequence_attribute. " unless updater.is_a?(Hash)
|
42
|
-
raise ":on in :updater should be a hash while setting sequence_attribute. " if updater.key?(:on) && !updater[:on].is_a?(Hash)
|
43
|
-
raise "Cannot use :via without :on in :updater while setting sequence_attribute. " if updater.key?(:via) && !updater.key?(:on)
|
44
|
-
|
45
|
-
updater_via = updater.delete(:via)
|
46
|
-
updater_on = updater.delete(:on) || updater
|
47
|
-
|
48
|
-
base_klass = search_base_klass(self.name, updater_via)
|
49
|
-
klass = reflected_klass(base_klass, updater_on.keys.first)
|
50
|
-
klass.constantize.class_eval do
|
51
|
-
after_save :activekit_sequence_sequenceable_callback
|
52
|
-
after_destroy :activekit_sequence_sequenceable_callback
|
53
|
-
|
54
|
-
define_method :activekit_sequence_sequenceable_callback do
|
55
|
-
inverse_assoc = self.class.search_inverse_assoc(self, updater_on)
|
56
|
-
position = positioning_method ? self.public_send(positioning_method) : nil
|
57
|
-
if inverse_assoc.respond_to?(:each)
|
58
|
-
inverse_assoc.each { |instance| instance.class.activekiter.sequence.update(record: instance, attribute_name: attribute_name, position: position) }
|
59
|
-
else
|
60
|
-
inverse_assoc.class.activekiter.sequence.update(record: inverse_assoc, attribute_name: attribute_name, position: position)
|
61
|
-
end
|
62
|
-
logger.info "ActiveSequence - Sequencing from #{self.class.name}: Done."
|
63
|
-
end
|
64
|
-
private :activekit_sequence_sequenceable_callback
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
def search_base_klass(classname, updater_via)
|
70
|
-
if updater_via.blank?
|
71
|
-
classname
|
72
|
-
elsif updater_via.is_a? Symbol
|
73
|
-
reflected_klass(classname, updater_via)
|
74
|
-
elsif updater_via.is_a? Hash
|
75
|
-
klass = reflected_klass(classname, updater_via.keys.first)
|
76
|
-
updater_via.values.first.is_a?(Hash) ? search_base_klass(klass, updater_via.values.first) : reflected_klass(klass, updater_via.values.first)
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
def reflected_klass(classname, key)
|
81
|
-
klass = classname.constantize.reflect_on_all_associations.map { |assoc| [assoc.name, assoc.klass.name] }.to_h[key]
|
82
|
-
raise "Could not find reflected klass for classname '#{classname}' and key '#{key}' while setting sequence_attribute" unless klass
|
83
|
-
klass
|
84
|
-
end
|
85
|
-
|
86
|
-
def search_inverse_assoc(klass_object, updater_on)
|
87
|
-
if updater_on.values.first.is_a?(Hash)
|
88
|
-
klass_object = klass_object.public_send(updater_on.values.first.keys.first)
|
89
|
-
search_inverse_assoc(klass_object, updater_on.values.first)
|
90
|
-
else
|
91
|
-
klass_object.public_send(updater_on.values.first)
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|