argon 1.1.0 → 1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f4bc7f87bd0b3e31f15e1c194ea49faac796ba68
4
- data.tar.gz: 2dced65f814d1d838b57800dd7336bf30f1fbd1d
3
+ metadata.gz: 705eb7f43e327e729691ed9b48ad18653ad33de2
4
+ data.tar.gz: 42c30f0c9b3d22930c5a2f64a5884024b5d54667
5
5
  SHA512:
6
- metadata.gz: e87960bccf2ec34fe5cf927566c8f714325ea79fe9e42eed57b374c5570148289f29e1ad44ccc0af0453b03620b92514c3008df551994c99bcedc5c9c476cdf0
7
- data.tar.gz: '0619768228c23bba7e01dd756e99d66d82c14be9d0d30c2d14987341fea1d9bd5450854b9cb942e509910f912aeedc9c04be8d0cb13836cab098b6bc6604e03a'
6
+ metadata.gz: 97c1a137e2496e1b041497f1e0258316c4b64c67f86196e680f23c730b5c884390dba1bb80faf32ca5a66362b70f876a0fb06075c79140daa353b81781470cb3
7
+ data.tar.gz: 4aa1da9170c820b95e2e2de0419399146218bf2db251d69fe44b61ea9ea50738b9674b0b1e67d9eb13fb89de99592365ef50cd1c8c667e2a488b78560df065d6
data/argon.gemspec CHANGED
@@ -27,4 +27,5 @@ Gem::Specification.new do |spec|
27
27
  spec.add_development_dependency "rails"
28
28
  spec.add_development_dependency "pry"
29
29
  spec.add_development_dependency "pry-byebug"
30
+ spec.add_development_dependency "symbolic_enum", "~> 1.1.0"
30
31
  end
data/lib/argon/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Argon
2
- VERSION = "1.1.0"
2
+ VERSION = "1.1.1"
3
3
  end
data/lib/argon.rb CHANGED
@@ -4,12 +4,14 @@ require 'argon/invalid_transition_error'
4
4
  require 'argon/invalid_parameter_error'
5
5
  require 'active_support/concern'
6
6
  require 'active_support/inflector'
7
+ require 'symbolic_enum'
7
8
  require 'pry-byebug'
8
9
 
9
10
  module Argon
10
11
  extend ActiveSupport::Concern
11
12
  extend ActiveSupport::Inflector
12
13
  include ActiveSupport::Inflector
14
+ include SymbolicEnum
13
15
 
14
16
  module ClassMethods
15
17
  def state_machine(mapping)
@@ -104,11 +106,11 @@ module Argon
104
106
  registered_edge_pairs << [from, to]
105
107
  end
106
108
 
107
- raise Argon::Error.new("`on_successful_transition` must be a lambda of signature `(from:, to:)`") if !on_successful_transition.nil? && !on_successful_transition.is_a?(Proc)
108
- raise Argon::Error.new("`on_successful_transition` must be a lambda of signature `(from:, to:)`") if on_successful_transition.parameters.to_set != [[:keyreq, :from],[:keyreq, :to]].to_set
109
+ raise Argon::Error.new("`on_successful_transition` must be a lambda of signature `(record:, from:, to:)`") if !on_successful_transition.nil? && !on_successful_transition.is_a?(Proc)
110
+ raise Argon::Error.new("`on_successful_transition` must be a lambda of signature `(record:, from:, to:)`") if on_successful_transition.parameters.to_set != [[:keyreq, :record],[:keyreq, :from],[:keyreq, :to]].to_set
109
111
 
110
- raise Argon::Error.new("`on_failed_transition` must be a lambda of signature `(from:, to:)`") if !on_failed_transition.nil? && !on_failed_transition.is_a?(Proc)
111
- raise Argon::Error.new("`on_failed_transition` must be a lambda of signature `(from:, to:)`") if on_failed_transition.parameters.to_set != [[:keyreq, :from],[:keyreq, :to]].to_set
112
+ raise Argon::Error.new("`on_failed_transition` must be a lambda of signature `(record:, from:, to:)`") if !on_failed_transition.nil? && !on_failed_transition.is_a?(Proc)
113
+ raise Argon::Error.new("`on_failed_transition` must be a lambda of signature `(record:, from:, to:)`") if on_failed_transition.parameters.to_set != [[:keyreq, :record],[:keyreq, :from],[:keyreq, :to]].to_set
112
114
 
113
115
  events_list.each do |event_name|
114
116
  end
@@ -130,24 +132,7 @@ module Argon
130
132
  self.class_variable_get(:@@state_machines || {})
131
133
  end
132
134
 
133
- # Replicating enum functionality (partially)
134
- define_singleton_method("#{ field.to_s.pluralize }") do
135
- states_map
136
- end
137
-
138
- reverse_states_map = states_map.map{|v| [v[1],v[0]]}.to_h
139
-
140
- define_method(field) do
141
- reverse_states_map[self[field]]
142
- end
143
-
144
- states_map.each_pair do |state_name, state_value|
145
- scope state_name, -> { where(field => state_value) }
146
-
147
- define_method("#{ state_name }?".to_sym) do
148
- self[field] == state_value
149
- end
150
- end
135
+ symbolic_enum field => states_map, disable_setters: true
151
136
 
152
137
  edges_list.each do |edge_details|
153
138
  from = edge_details[:from]
@@ -176,7 +161,7 @@ module Argon
176
161
  end
177
162
 
178
163
  if self.send(field) != from
179
- on_failed_transition.call(from: self.send(field), to: to)
164
+ on_failed_transition.call(record: self, from: self.send(field), to: to)
180
165
  raise Argon::InvalidTransitionError.new("Invalid state transition")
181
166
  end
182
167
 
@@ -198,11 +183,11 @@ module Argon
198
183
  end
199
184
  end
200
185
  rescue => e
201
- on_failed_transition.call(from: self.send(field), to: to)
186
+ on_failed_transition.call(record: self, from: self.send(field), to: to)
202
187
  raise e
203
188
  end
204
189
 
205
- on_successful_transition.call(from: from, to: to)
190
+ on_successful_transition.call(record: self, from: from, to: to)
206
191
 
207
192
  unless after_lock_callback.nil?
208
193
  if args.empty?
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: argon
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ajith Hussain
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-10-11 00:00:00.000000000 Z
11
+ date: 2017-12-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: symbolic_enum
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 1.1.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 1.1.0
97
111
  description:
98
112
  email:
99
113
  - csy0013@googlemail.com