activekit 0.2.3.dev4 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 62f5b0538c0eb5994bdb8aeb913c33e8a15dcc65c8f2c39ce2e090cfebc783e1
4
- data.tar.gz: 6ba99ac12be26299974e57b32f4a66b36fb1ab169cd5ebbb47c5b411a1d07a31
3
+ metadata.gz: 630c8d871f28fedaf525eecbf06fdfb396bba0f62282ec3a8d7d9ef359a833c4
4
+ data.tar.gz: 154de328d7cc8e4520ff9f5f5f57ee6b1e73cf0df352d2aaee97387dca9a06a1
5
5
  SHA512:
6
- metadata.gz: b3e3f6176fab57d7c4cf3e417c18332d14d74c1ec0402236d4966f4875020f418e0adb8153b7d7ce413b95f9a3248e7113c94ca326e48633a0a15234b2ae9f23
7
- data.tar.gz: 03665e96860846157d569c5df192000f3be9d87c76a4272841a0076f7594f10cdac9d465696f8633108c78df5f9a54bcd4938e4bc195b23bb143790338f8a274
6
+ metadata.gz: 68aaf23851ac2ba3ae9d73eb4474a3c7fe789c7e6f6e61c0d0e85d23a77f159c9e219cd635a28f99cc215f0b4605e43046196ebbf384f172e4ac0bd0f33fce95
7
+ data.tar.gz: 0753d639192b574bda48eee23df69d8f23e95d24c6c03f7571b4fb87c28a99a08bfd346a30b7ff0b0a271a890d4878e2cd37c7aa50bf912d0f21d29014e968f1
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # ActiveKit
2
- Short description and motivation.
2
+ Add the essential kit for rails ActiveRecord models and be happy.
3
3
 
4
4
  ## Usage
5
5
  How to use my plugin.
@@ -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
- activekit_runner(request) do
12
+ activekit_run(request) do
13
13
  @app.call(env)
14
14
  end
15
15
  end
16
16
 
17
17
  private
18
18
 
19
- # Here constantize is used to get the latest reloaded class as per the below link.
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
@@ -4,7 +4,6 @@ module ActiveKit
4
4
 
5
5
  autoload :Activekiter
6
6
  autoload :Ensure
7
- autoload :Middleware
8
7
  autoload :Relation
9
8
  end
10
9
  end
@@ -4,6 +4,8 @@ module ActiveKit
4
4
  config.eager_load_namespaces << ActiveKit
5
5
 
6
6
  initializer "active_kit.add_middleware" do |app|
7
+ require "active_kit/base/middleware"
8
+
7
9
  app.middleware.use ActiveKit::Base::Middleware
8
10
  end
9
11
 
@@ -1,3 +1,3 @@
1
1
  module ActiveKit
2
- VERSION = '0.2.3.dev4'
2
+ VERSION = '0.2.3'
3
3
  end
data/lib/active_kit.rb CHANGED
@@ -5,6 +5,5 @@ module ActiveKit
5
5
  extend ActiveSupport::Autoload
6
6
 
7
7
  autoload :Base
8
- autoload :Schedule
9
8
  autoload :Sequence
10
9
  end
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.dev4
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - plainsource
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-19 00:00:00.000000000 Z
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,9 @@ dependencies:
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
32
  version: 6.1.3.1
33
- description: The essential kit for rails ActiveRecord models.
33
+ description: Add the essential kit for rails ActiveRecord models and be happy.
34
34
  email:
35
- - plainsource@humanmind.me
35
+ - plainsource@timeboard.org
36
36
  executables: []
37
37
  extensions: []
38
38
  extra_rdoc_files: []
@@ -59,10 +59,6 @@ files:
59
59
  - lib/active_kit/base/middleware.rb
60
60
  - lib/active_kit/base/relation.rb
61
61
  - 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
62
  - lib/active_kit/sequence.rb
67
63
  - lib/active_kit/sequence/sequence.rb
68
64
  - lib/active_kit/sequence/sequenceable.rb
@@ -86,13 +82,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
86
82
  version: '0'
87
83
  required_rubygems_version: !ruby/object:Gem::Requirement
88
84
  requirements:
89
- - - ">"
85
+ - - ">="
90
86
  - !ruby/object:Gem::Version
91
- version: 1.3.1
87
+ version: '0'
92
88
  requirements: []
93
89
  rubygems_version: 3.1.2
94
90
  signing_key:
95
91
  specification_version: 4
96
- summary: ActiveKit adds useful day-to-day features to ActiveRecord to help make life
97
- easy.
92
+ summary: Add useful features to ActiveRecord
98
93
  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
@@ -1,8 +0,0 @@
1
- module ActiveKit
2
- module Schedule
3
- extend ActiveSupport::Autoload
4
-
5
- autoload :Middleware
6
- autoload :Schedule
7
- end
8
- end