tiny_state 0.1.0 → 0.2.0
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 +4 -4
- data/README.md +2 -4
- data/lib/class_attribute.rb +36 -0
- data/lib/tiny_state/event.rb +5 -3
- data/lib/tiny_state/tiny_state.rb +8 -7
- data/lib/tiny_state/version.rb +1 -1
- data/tiny_state.gemspec +0 -2
- metadata +4 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b604878efa6bc8ea4ca885db8dc94f9452fbb13bec5c7918d0b202fe70fb8b82
|
4
|
+
data.tar.gz: 85f3311becd23783c625a4f4a197b3d1cbd1db3a6e80bd9ff95404cdb54ae0bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6cba3d24f51114e24c78fe26fee9bf1979648f81d98afdd04b364e95fea6e7695918dbe38deb2b20247db01f6d1b70c73e2e009d7fc2df20ff0dee352b0186a6
|
7
|
+
data.tar.gz: b0daf6b567beb6694fa3117e521f9c87c94f36a0cc85e553f3ffd036b678a03192789a3b93427930fd949268aba36aaa4aff2da2d39f2d16be7115fba29cb520
|
data/README.md
CHANGED
@@ -14,12 +14,10 @@ Tiny State is a library to add a state machine to any Ruby class. It has a few d
|
|
14
14
|
|
15
15
|
## Getting Started
|
16
16
|
|
17
|
-
Tiny State is
|
18
|
-
|
19
|
-
Add it to your Gemfile like so:
|
17
|
+
Tiny State is [published on Rubygems](https://rubygems.org/gems/tiny_state), so just add it to your Gemfile:
|
20
18
|
|
21
19
|
```ruby
|
22
|
-
gem "tiny_state"
|
20
|
+
gem "tiny_state"
|
23
21
|
```
|
24
22
|
|
25
23
|
## Usage
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module ClassAttribute
|
2
|
+
def self.included(base)
|
3
|
+
base.extend ClassMethods
|
4
|
+
end
|
5
|
+
|
6
|
+
module ClassMethods
|
7
|
+
# Based on `class_attribute` from Rails, without the options we don't use.
|
8
|
+
# https://github.com/rails/rails/blob/main/activesupport/lib/active_support/core_ext/class/attribute.rb
|
9
|
+
def tiny_class_attribute(name, default: nil)
|
10
|
+
class_methods, methods = [], []
|
11
|
+
|
12
|
+
methods << <<~RUBY
|
13
|
+
def #{name}
|
14
|
+
defined?(@#{name}) ? @#{name} : self.class.#{name}
|
15
|
+
end
|
16
|
+
RUBY
|
17
|
+
|
18
|
+
class_methods << <<~RUBY
|
19
|
+
def #{name}=(value)
|
20
|
+
define_method(:#{name}) { value } if singleton_class?
|
21
|
+
define_singleton_method(:#{name}) { value }
|
22
|
+
value
|
23
|
+
end
|
24
|
+
RUBY
|
25
|
+
|
26
|
+
methods << <<~RUBY
|
27
|
+
attr_writer :#{name}
|
28
|
+
RUBY
|
29
|
+
|
30
|
+
location = caller_locations(1, 1).first
|
31
|
+
class_eval(["class << self", *class_methods, "end", *methods].join(";").tr("\n", ";"), location.path, location.lineno)
|
32
|
+
|
33
|
+
public_send(:"#{name}=", default)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/tiny_state/event.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
-
require "
|
1
|
+
require "./lib/class_attribute"
|
2
2
|
|
3
3
|
module TinyState
|
4
4
|
class Event
|
5
|
-
|
6
|
-
|
5
|
+
include ClassAttribute
|
6
|
+
|
7
|
+
tiny_class_attribute :from_states
|
8
|
+
tiny_class_attribute :to_state
|
7
9
|
attr_reader :resource, :attribute
|
8
10
|
|
9
11
|
def self.transitions(from:, to:)
|
@@ -1,14 +1,15 @@
|
|
1
|
-
require "
|
2
|
-
require "active_support/concern"
|
1
|
+
require "./lib/class_attribute"
|
3
2
|
|
4
3
|
module TinyState
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
def self.included(base)
|
5
|
+
base.extend ClassMethods
|
6
|
+
base.class_eval do
|
7
|
+
include ClassAttribute
|
8
|
+
tiny_class_attribute :tiny_state_machines, default: {}
|
9
|
+
end
|
9
10
|
end
|
10
11
|
|
11
|
-
|
12
|
+
module ClassMethods
|
12
13
|
def tiny_state(attribute = :state, &)
|
13
14
|
state_machine = TinyState::StateMachine.new(attribute:)
|
14
15
|
|
data/lib/tiny_state/version.rb
CHANGED
data/tiny_state.gemspec
CHANGED
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tiny_state
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dennis Paagman
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-05-
|
12
|
-
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: activesupport
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '7.1'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '7.1'
|
11
|
+
date: 2024-05-30 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
27
13
|
description: A tiny Ruby state machine using Plain Ruby Objects (PORO).
|
28
14
|
email:
|
29
15
|
- dennis@paagman.dev
|
@@ -38,6 +24,7 @@ files:
|
|
38
24
|
- README.md
|
39
25
|
- Rakefile
|
40
26
|
- config/quickdraw.rb
|
27
|
+
- lib/class_attribute.rb
|
41
28
|
- lib/tiny_state.rb
|
42
29
|
- lib/tiny_state/errors.rb
|
43
30
|
- lib/tiny_state/event.rb
|