aircts_as_state_machine 0.1.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8da8aad591951b2ca414d1c7b80cb7f1d6bc75458fe7ba0d97e93f08263ff9b6
4
+ data.tar.gz: da18e4691c0c99ef55a394282ac1ae0c2a0f82d1741cf40e51569b134ed3278e
5
+ SHA512:
6
+ metadata.gz: af0e144cd79e23ef9e3ee8eb1e5b78595b471c983a014c750cc02bc602ffaef44392ea63e50844da619d0ccd96e1686b2aca8e785f242ac13cb46b3c96d262a1
7
+ data.tar.gz: '0941d1d0cdb87d13553eefecb20d494be95852267e6c1d77f50f5db8470e13cf19081774f4a4332867ac946daf945197cd1d39ba3093f34130f871da4916b927'
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
data/README.md ADDED
@@ -0,0 +1,58 @@
1
+ # aircts_as_state_machine
2
+ [aasm](https://github.com/aasm/aasm) support for Airrecord tables.
3
+
4
+ currently only works with my [airrecord fork](https://github.com/24c02/airrecord)
5
+
6
+ ## usage:
7
+ don't
8
+
9
+ but if you must:
10
+ ```ruby
11
+ require "aircts_as_state_machine"
12
+
13
+ Airrecord.api_key = "pat3verysoftcats"
14
+
15
+ class Shipment < AirctsAsStateMachine; # instead of Airrecord::Table
16
+ self.base_key = 'appsomething'
17
+ self.table_name = 'tblsomething'
18
+
19
+ aasm column: "Status" do # Status should be a single-select field in your base
20
+ state :ready, :mailed
21
+
22
+ event mark_mailed do
23
+ transitions from: :ready, to: :mailed
24
+ before do |postage_cost|
25
+ self["Postage Cost"] = postage_cost
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ x = Shipment.find "recYaself"
32
+
33
+ # this sets State to "mailed" and Postage Cost to 3.50
34
+ x.mark_mailed 3.50
35
+ # but nothing persists to the cloud until
36
+ x.save
37
+
38
+ # or...
39
+ x["Recipient"] = "nora"
40
+ x.mark_mailed! 3.50
41
+
42
+ # with the !, the transition gets fired in a transaction, so the AASM column
43
+ # and any fields modified in the callbacks are immediately persisted in a single
44
+ # PATCH request, but anything modified outside (like Recipient) waits for save.
45
+ ```
46
+
47
+ # caveats
48
+ i'm trusting this in prod but you probably shouldn't
49
+
50
+ i wrote this code but i do not understand it
51
+
52
+ the real horrors are in the """"""[transaction support](https://github.com/24c02/airrecord/blob/5ae56c166b29f4ae2723edce99970e9c8e0d59a3/lib/airrecord/table.rb#L237)"""""" this needed airrecord to have
53
+
54
+ it's not very good
55
+
56
+ ...
57
+
58
+ k cya
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+
5
+ require "rubocop/rake_task"
6
+
7
+ RuboCop::RakeTask.new
8
+
9
+ task default: :rubocop
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "norairrecord"
4
+ require "aasm"
5
+
6
+ module AASM
7
+ module Persistence
8
+ # mix this in to taste
9
+ module AirrecordPersistence
10
+ def self.included(base)
11
+ base.extend AASM::Persistence::Base::ClassMethods
12
+ base.extend ClassMethods
13
+
14
+ base.class_eval do
15
+ attr_accessor :_transition_changes
16
+ end
17
+ end
18
+
19
+ def aasm_read_state(name = :default)
20
+ state = self[self.class.aasm(name).attribute_name.to_s]
21
+ state&.to_sym
22
+ end
23
+
24
+ def aasm_write_state_without_persistence(state, name = :default)
25
+ self[self.class.aasm(name).attribute_name.to_s] = state.to_s
26
+ end
27
+
28
+ def aasm_fire_event(state_machine_name, name, options, *args, &block)
29
+ return super unless options[:persist]
30
+
31
+ transaction do
32
+ super
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+
39
+ # inherit from this as you would Airrecord::Table
40
+ class AirctsAsStateMachine < Norairrecord::Table
41
+ include AASM
42
+ include AASM::Persistence::AirrecordPersistence
43
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: aircts_as_state_machine
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - 24c02
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-12-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: norairrecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: don't
28
+ email:
29
+ - nora@hcb.pizza
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".rubocop.yml"
35
+ - README.md
36
+ - Rakefile
37
+ - lib/aircts_as_state_machine.rb
38
+ homepage: https://github.com/24c02/aircts_as_state_machine
39
+ licenses: []
40
+ metadata:
41
+ homepage_uri: https://github.com/24c02/aircts_as_state_machine
42
+ source_code_uri: https://github.com/24c02/aircts_as_state_machine
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: 2.6.0
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ requirements: []
58
+ rubygems_version: 3.5.11
59
+ signing_key:
60
+ specification_version: 4
61
+ summary: aasm persistence for airrecord tables
62
+ test_files: []