solidstate 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
  SHA1:
3
- metadata.gz: 10ee93a954561985d002e7f8db5ffe186a792bba
4
- data.tar.gz: e979280cea908e17a924718f7f20a247d79c11b9
3
+ metadata.gz: 2440bdd08c03d227ce1343783e7fc863d197db67
4
+ data.tar.gz: 56ea18976e16dce884b21b2b1bc0a94a7be1b564
5
5
  SHA512:
6
- metadata.gz: 3480386e65adfdd682c7bd05a4a67d49a50660ac102b16fc7cbe7c334d50ab3829989b0e710af6a6e6f8d54d7b1ec352736727adb2f7955a2664a4103c70ce01
7
- data.tar.gz: 1ccbbca8ab19e933ff4894036fdf46f9c48daa1c264d37d573917303848f1b34d90e269f2de771a451e508028d697ebf381c8d3cacabf497701e61c41f0c9ace
6
+ metadata.gz: 6d59cea2fb06b79b7f660cd4dcd8fff0927e843760434f3eba84edafcf87e7671a3577b06632b3eba225520eae0e0104fbb2445db1f5fd6addf493dcf42c4286
7
+ data.tar.gz: a1f6bb99d36c2ef57ea9914477d6863ed811895cfc817df780bfac72bde5cb082c10b53e1bf19f468af9e01e1900010118ddff87d7ebed846a24dc386ea58f95
data/README.md CHANGED
@@ -50,29 +50,29 @@ Minuscule but solid state machine for Ruby classes. The only dependency is that
50
50
  include SolidState
51
51
 
52
52
  states :inactive, :active, :unsubscribed, :disabled do
53
- transitions :from => :inactive, :to => :active
54
- transitions :from => :active, :to => [:unsubscribed, :disabled]
55
- transitions :from => :unsubscribed, :to => :active
53
+ transitions from: :inactive, to: :active
54
+ transitions from: :active, to: [:unsubscribed, :disabled]
55
+ transitions from: :unsubscribed, to: :active
56
56
  end
57
57
  end
58
58
 
59
59
  s = Subscriber.new
60
- s.state # => 'inactive'
60
+ s.state # => 'inactive'
61
61
 
62
62
  # since we declared transitions, we can now call #{state}! which
63
63
  # checks whether the instance can transition to that state and
64
64
  # if so, sets the new state and optionally saves the record.
65
65
 
66
- s.active! # => true
66
+ s.active! # => true
67
67
 
68
68
  s.inactive! # => raises InvalidTransitionError
69
69
 
70
70
  # this also works outside transition methods, of course.
71
- s.reload # => true
72
- s.active? # => true
71
+ s.reload # => true
72
+ s.active? # => true
73
73
 
74
74
  s.state = 'inactive'
75
- s.valid? # => false
75
+ s.valid? # => false
76
76
 
77
77
  # the last trick this library does is that it optionally lets you
78
78
  # declare callback methods that are called whenever a transition
data/lib/solidstate.rb CHANGED
@@ -8,8 +8,8 @@ module SolidState
8
8
  module ClassMethods
9
9
 
10
10
  def states(*list, &block)
11
- raise "This is not a list of names" unless list.first.is_a?(String)
12
11
  list = list.collect(&:to_s)
12
+ raise "This is not a list of names" unless list.first.respond_to?(:downcase)
13
13
 
14
14
  @@states = list
15
15
  @@state_transitions = {}
@@ -62,6 +62,7 @@ module SolidState
62
62
 
63
63
  if !respond_to?(:valid?) or (valid? && save)
64
64
  send("once_#{dest}", from) if respond_to?("once_#{dest}")
65
+ send("once_not_#{from}", dest) if respond_to?("once_not_#{from}")
65
66
  true
66
67
  else
67
68
  false
@@ -71,11 +72,19 @@ module SolidState
71
72
  end
72
73
  end
73
74
 
75
+ def once_not_subscribed
76
+
77
+ end
78
+
79
+ def after
80
+
74
81
  def set_state(new_state)
75
82
  return false unless can_transition_to?(new_state)
76
83
  self.state = new_state
77
84
  end
78
85
 
86
+ private
87
+
79
88
  def ensure_valid_transition
80
89
  if send("#{STATE_ATTRIBUTE}_changed?") and !can_transition_to?(state)
81
90
  errors.add(STATE_ATTRIBUTE, "can't transition from current state to #{state}")
data/solidstate.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "solidstate"
5
- s.version = '0.1.0'
5
+ s.version = '0.2.0'
6
6
  s.platform = Gem::Platform::RUBY
7
7
  s.authors = ['Tomás Pollak']
8
8
  s.email = ['tomas@forkhq.com']
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solidstate
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
  - Tomás Pollak