can_has_state 0.4.0 → 0.6.0

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
- SHA1:
3
- metadata.gz: 8f5ac5880eb7dde62694993ffa17483b6178f7a8
4
- data.tar.gz: 642ffbb9ac33405c47ff5abb0ecbc85d1cc68869
2
+ SHA256:
3
+ metadata.gz: a3b45a0fd9887bd419ffa6fc89e6a7a566878fbfc8c60f4c34c3e5717659087c
4
+ data.tar.gz: 57b418edcb7d1403b7e57b5fb1f5665e3cf8fc4b2e68612d56c17627ff16cece
5
5
  SHA512:
6
- metadata.gz: 175d46b7e64d3f0ce1a041d1bd4d1f308b3a4bc49080cbf1818044e0be883760a693c051637146af59dc30d3aff97d7e883ff35632285334e4222cb2c8c9e114
7
- data.tar.gz: db19b6e893d808e79f810ad032711837073199fc2367454eb9e2b876005a263fdc44a50a43a2e84e91c0f5ec608e3906b914c3b4c129a1f28db88bef3fd81faa
6
+ metadata.gz: 9bbdc97653a0d9087808667b1a26c28f7e2a6f8a2088f315bebad7da575ef31f2cb73e62858cf77875c562496a185e9668984f272c8e2de422cc16de272b86ce
7
+ data.tar.gz: b69e6e85fc0937e3a9437f747d590ed9f532677b6004f15946c3f2fae6573728a530ada4d1827e15777b4f3a4063d941a5170f9bc83f9070246a6ca39000a3ad
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2012 thomas morgan
1
+ Copyright 2012-2021 thomas morgan
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -253,4 +253,4 @@ because the initial state value changed from nil to the initial state.
253
253
 
254
254
  ## Compatibility ##
255
255
 
256
- Tested with Ruby 1.9 and ActiveSupport and ActiveModel 4.0.
256
+ Tested with Ruby 2.3-2.6+ and ActiveSupport and ActiveModel 5.2-6.1+.
data/lib/can_has_state.rb CHANGED
@@ -5,4 +5,7 @@ require 'active_model'
5
5
  require "can_has_state/#{f}"
6
6
  end
7
7
 
8
+ # require 'active_support/i18n'
9
+ I18n.load_path << File.dirname(__FILE__) + '/can_has_state/locale/en.yml'
10
+
8
11
  require 'can_has_state/railtie' if defined?(Rails)
@@ -28,7 +28,7 @@ module CanHasState
28
28
 
29
29
  # TODO: turn even guards into types of triggers ... then support :guard as a trigger param
30
30
  guards = []
31
- message = "has invalid transition from %{from} to %{to}"
31
+ message = :invalid_transition
32
32
  # TODO: differentiate messages for :from errors vs. :guard errors
33
33
 
34
34
  options.each do |key, val|
@@ -0,0 +1,5 @@
1
+ en:
2
+ errors:
3
+ messages:
4
+ invalid_state: "is not in a known state"
5
+ invalid_transition: "has an invalid transition from %{from} to %{to}"
@@ -0,0 +1,5 @@
1
+ es:
2
+ errors:
3
+ messages:
4
+ invalid_state: "no está en un estado conocido"
5
+ invalid_transition: "tiene una transición no válida de %{from} a %{to}"
@@ -71,7 +71,11 @@ module CanHasState
71
71
  # clear record of called triggers
72
72
  @triggers_called[column] = nil
73
73
 
74
- from, to = send("#{column}_was"), send(column)
74
+ if respond_to?("#{column}_before_last_save") # rails 5.1+
75
+ from, to = send("#{column}_before_last_save"), send(column)
76
+ else
77
+ from, to = send("#{column}_was"), send(column)
78
+ end
75
79
  next if from == to
76
80
  sm.trigger(self, from, to, :deferred)
77
81
  end
@@ -83,17 +87,17 @@ module CanHasState
83
87
  from, to = send("#{column}_was"), send(column)
84
88
  next if from == to
85
89
  if !sm.known?(to)
86
- err << [column, "is not in a known state"]
90
+ err << [column, :invalid_state]
87
91
  elsif !sm.allow?(self, to) #state_machine_allow?(column, to)
88
- err << [column, sm.message(to) % {:from=>from, :to=>to}]
92
+ err << [column, sm.message(to), {from: from, to: to}]
89
93
  end
90
94
  end
91
95
  err
92
96
  end
93
97
 
94
98
  def can_has_valid_state_machines
95
- can_has_state_errors.each do |(column, msg)|
96
- errors.add column, msg
99
+ can_has_state_errors.each do |(column, msg, opts)|
100
+ errors.add column, msg, opts||{}
97
101
  end
98
102
  end
99
103
 
@@ -1,3 +1,3 @@
1
1
  module CanHasState
2
- VERSION = '0.4.0'
2
+ VERSION = '0.6.0'
3
3
  end
@@ -24,8 +24,8 @@ class Account
24
24
 
25
25
  def fake_persist
26
26
  if valid?
27
- # just reset dirty tracking and pretend all is good
28
- changed_attributes.clear
27
+ # reset dirty tracking as if we had persisted
28
+ changes_applied
29
29
  true
30
30
  end
31
31
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: can_has_state
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - thomas morgan
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-13 00:00:00.000000000 Z
11
+ date: 2021-05-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -16,40 +16,20 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '4'
19
+ version: '5.2'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '6'
22
+ version: '6.2'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: '4'
29
+ version: '5.2'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '6'
33
- - !ruby/object:Gem::Dependency
34
- name: activesupport
35
- requirement: !ruby/object:Gem::Requirement
36
- requirements:
37
- - - ">="
38
- - !ruby/object:Gem::Version
39
- version: '4'
40
- - - "<"
41
- - !ruby/object:Gem::Version
42
- version: '6'
43
- type: :runtime
44
- prerelease: false
45
- version_requirements: !ruby/object:Gem::Requirement
46
- requirements:
47
- - - ">="
48
- - !ruby/object:Gem::Version
49
- version: '4'
50
- - - "<"
51
- - !ruby/object:Gem::Version
52
- version: '6'
32
+ version: '6.2'
53
33
  - !ruby/object:Gem::Dependency
54
34
  name: minitest
55
35
  requirement: !ruby/object:Gem::Requirement
@@ -93,6 +73,8 @@ files:
93
73
  - lib/can_has_state.rb
94
74
  - lib/can_has_state/definition.rb
95
75
  - lib/can_has_state/dirty_helper.rb
76
+ - lib/can_has_state/locale/en.yml
77
+ - lib/can_has_state/locale/es.yml
96
78
  - lib/can_has_state/machine.rb
97
79
  - lib/can_has_state/railtie.rb
98
80
  - lib/can_has_state/version.rb
@@ -100,9 +82,10 @@ files:
100
82
  - test/can_has_state_test.rb
101
83
  - test/test_helper.rb
102
84
  homepage: https://github.com/zarqman/can_has_state
103
- licenses: []
85
+ licenses:
86
+ - MIT
104
87
  metadata: {}
105
- post_install_message:
88
+ post_install_message:
106
89
  rdoc_options: []
107
90
  require_paths:
108
91
  - lib
@@ -117,9 +100,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
100
  - !ruby/object:Gem::Version
118
101
  version: '0'
119
102
  requirements: []
120
- rubyforge_project:
121
- rubygems_version: 2.6.12
122
- signing_key:
103
+ rubygems_version: 3.0.9
104
+ signing_key:
123
105
  specification_version: 4
124
106
  summary: Super simple state machine for ActiveModel
125
107
  test_files: