activekit 0.2.3.dev3 → 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: 3767389029cd4104d5b520e38e5667b413d187a71c48ed9b5b2c1ad48cbe7b99
4
- data.tar.gz: 3a1253ea5a7bf16a30ee3b07aa0eed4948eee4054ce5e65633ab5d8a47f14341
3
+ metadata.gz: b1e6c87aec8ba8d6e11b11d7c95ffb3f47f553a4965705bb49bfec492b6c2991
4
+ data.tar.gz: cb43e632e5e1e2cf47caf219a48c9359959db8885a8d8c3955e70be4cf01cf9a
5
5
  SHA512:
6
- metadata.gz: c6b09929310c0645b706f5d08654047a413143d2fb7176ee39fce282949d72ba6f2ff9b4603fc1376e67d06c5264fa9ea8d17802379da1cd2635e1a24526803e
7
- data.tar.gz: 3ae4a9b3e491f259cf4301127c6d8fd7b8847a18189baa83cde3633c42b29b212975bc8f3c4730153d1c5d004ebe784a2c4202ac3ce506cda8eb402d359c06ce
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
@@ -1,10 +1,6 @@
1
1
  module ActiveKit
2
2
  module Base
3
3
  class Ensure
4
- def self.middleware_for!(request:)
5
- ActiveKit::Schedule::Middleware.run(request: request)
6
- end
7
-
8
4
  def self.setup_for!(current_class:)
9
5
  current_class.class_eval do
10
6
  unless self.reflect_on_association :activekit_association
@@ -9,16 +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
- def activekit_runner(request, &blk)
20
- Ensure.middleware_for!(request: request)
21
-
19
+ def activekit_run(request, &blk)
22
20
  yield
23
21
  end
24
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.dev3'
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.dev3
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: Add an activekit text column to your model and use all ActiveKit features.
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
@@ -70,11 +67,11 @@ files:
70
67
  - lib/active_kit/version.rb
71
68
  - lib/activekit.rb
72
69
  - lib/tasks/active_kit_tasks.rake
73
- homepage: https://www.timeboard.org/plainsource/activekit
70
+ homepage: https://github.com/plainsource/activekit
74
71
  licenses:
75
72
  - MIT
76
73
  metadata:
77
- homepage_uri: https://www.timeboard.org/plainsource/activekit
74
+ homepage_uri: https://github.com/plainsource/activekit
78
75
  post_install_message:
79
76
  rdoc_options: []
80
77
  require_paths:
@@ -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 many useful day-to-day features to ActiveRecord to help make
97
- many tasks 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