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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 312b61f20ffa06f30ae9c77de4eaf9839b5ccf6338a869425f05f7c871b7f55e
4
- data.tar.gz: 7229d0a178cf65d3b6f1b8f1ff8419400318915d2479a4fabb5703f223f8647d
3
+ metadata.gz: b604878efa6bc8ea4ca885db8dc94f9452fbb13bec5c7918d0b202fe70fb8b82
4
+ data.tar.gz: 85f3311becd23783c625a4f4a197b3d1cbd1db3a6e80bd9ff95404cdb54ae0bd
5
5
  SHA512:
6
- metadata.gz: 51f3601a4a992b0537f3de0ebf3d16c3be84bf2bbbdfff635489cb0a7f2cf6cf971e8fcb6ee90cdd7a7ad3d3653f45ba59e4949ad9015d9c9d8cd5eb03748a41
7
- data.tar.gz: 3ef88f8ea58f9d1ffa2940fd83a5b419cbe9518a23a7c5bd91f4aabb3c77b2da856beb2f7fcb627f8fc4fa44022a134d66b219fd6b7fdb4dd7c7e247700352d6
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 not published to Rubygems yet.
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", github: "djfpaagman/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
@@ -1,9 +1,11 @@
1
- require "active_support/core_ext/class/attribute"
1
+ require "./lib/class_attribute"
2
2
 
3
3
  module TinyState
4
4
  class Event
5
- class_attribute :from_states, instance_predicate: false
6
- class_attribute :to_state, instance_predicate: false
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 "active_support/core_ext/class/attribute"
2
- require "active_support/concern"
1
+ require "./lib/class_attribute"
3
2
 
4
3
  module TinyState
5
- extend ActiveSupport::Concern
6
-
7
- included do
8
- class_attribute :tiny_state_machines, instance_predicate: false, default: {}
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
- class_methods do
12
+ module ClassMethods
12
13
  def tiny_state(attribute = :state, &)
13
14
  state_machine = TinyState::StateMachine.new(attribute:)
14
15
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TinyState
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
data/tiny_state.gemspec CHANGED
@@ -29,6 +29,4 @@ Gem::Specification.new do |spec|
29
29
  spec.require_paths = ["lib"]
30
30
 
31
31
  spec.metadata["rubygems_mfa_required"] = "true"
32
-
33
- spec.add_dependency "activesupport", "~> 7.1"
34
32
  end
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.1.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-21 00:00:00.000000000 Z
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