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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 62f5b0538c0eb5994bdb8aeb913c33e8a15dcc65c8f2c39ce2e090cfebc783e1
4
- data.tar.gz: 6ba99ac12be26299974e57b32f4a66b36fb1ab169cd5ebbb47c5b411a1d07a31
3
+ metadata.gz: b1e6c87aec8ba8d6e11b11d7c95ffb3f47f553a4965705bb49bfec492b6c2991
4
+ data.tar.gz: cb43e632e5e1e2cf47caf219a48c9359959db8885a8d8c3955e70be4cf01cf9a
5
5
  SHA512:
6
- metadata.gz: b3e3f6176fab57d7c4cf3e417c18332d14d74c1ec0402236d4966f4875020f418e0adb8153b7d7ce413b95f9a3248e7113c94ca326e48633a0a15234b2ae9f23
7
- data.tar.gz: 03665e96860846157d569c5df192000f3be9d87c76a4272841a0076f7594f10cdac9d465696f8633108c78df5f9a54bcd4938e4bc195b23bb143790338f8a274
6
+ metadata.gz: 89443ef5fde9805d9033d19e9a2b3f148eaa38128e372a3affd7c8831f0e6988ff92e9227fbc7275cb68e9d0a5db5a38c8fc7dbb49969c157c54604eb3f17404
7
+ data.tar.gz: b2d3fe63c09a5351d5cfcf6c69192b39ba35242ba4ba279915473d737c5de72807d62b125b7339af0628eb093730b9a51433253b17bd8cc3d452efe0a7ed8695
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # ActiveKit
2
- Short description and motivation.
2
+ ActiveKit adds useful day-to-day features to ActiveRecord to make the rails developer 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.dev5'
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.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-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,10 @@ 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: ActiveKit adds useful day-to-day features to ActiveRecord to make the
34
+ rails developer happy.
34
35
  email:
35
- - plainsource@humanmind.me
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: ActiveKit adds useful day-to-day features to ActiveRecord to help make life
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
@@ -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