enum_machine 0.1.0 → 2.0.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/.rubocop.yml +4 -1
- data/Gemfile +8 -8
- data/Gemfile.lock +106 -74
- data/README.md +238 -16
- data/Rakefile +3 -3
- data/docs/MIGRATING_FROM_RAILS_STRING_ENUM.ru.md +54 -0
- data/lib/enum_machine/attribute_persistence_methods.rb +27 -0
- data/lib/enum_machine/build_enum_class.rb +61 -0
- data/lib/enum_machine/build_value_class.rb +79 -0
- data/lib/enum_machine/driver_active_record.rb +89 -31
- data/lib/enum_machine/driver_simple_class.rb +33 -33
- data/lib/enum_machine/machine.rb +46 -18
- data/lib/enum_machine/version.rb +1 -3
- data/lib/enum_machine.rb +24 -10
- metadata +26 -23
- data/lib/enum_machine/build_attribute.rb +0 -123
- data/lib/enum_machine/build_class.rb +0 -41
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EnumMachine
|
4
|
+
module BuildEnumClass
|
5
|
+
def self.call(enum_values:, i18n_scope:, value_class:, machine: nil)
|
6
|
+
aliases = machine&.instance_variable_get(:@aliases) || {}
|
7
|
+
|
8
|
+
Class.new do
|
9
|
+
define_singleton_method(:machine) { machine } if machine
|
10
|
+
define_singleton_method(:values) { enum_values.map { value_class.new(_1).freeze } }
|
11
|
+
|
12
|
+
value_attribute_mapping = values.to_h { [_1.to_s, _1] }
|
13
|
+
define_singleton_method(:value_attribute_mapping) { value_attribute_mapping }
|
14
|
+
define_singleton_method(:[]) do |enum_value|
|
15
|
+
key = enum_value.to_s
|
16
|
+
# Check for key existence because `[]` will call `default_proc`, and we don’t want that
|
17
|
+
value_attribute_mapping[key] if value_attribute_mapping.key?(key)
|
18
|
+
end
|
19
|
+
|
20
|
+
if i18n_scope
|
21
|
+
def self.values_for_form(specific_values = nil) # rubocop:disable Gp/OptArgParameters
|
22
|
+
(specific_values || values).map { |v| [human_name_for(v), v] }
|
23
|
+
end
|
24
|
+
|
25
|
+
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
26
|
+
# def self.human_name_for(name)
|
27
|
+
# ::I18n.t(name, scope: "enums.test_model", default: name)
|
28
|
+
# end
|
29
|
+
|
30
|
+
def self.human_name_for(name)
|
31
|
+
::I18n.t(name, scope: "enums.#{i18n_scope}", default: name)
|
32
|
+
end
|
33
|
+
RUBY
|
34
|
+
end
|
35
|
+
|
36
|
+
enum_values.each do |enum_value|
|
37
|
+
const_set enum_value.underscore.upcase, enum_value.to_s.freeze
|
38
|
+
end
|
39
|
+
|
40
|
+
aliases.each_key do |key|
|
41
|
+
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
42
|
+
# def self.forming
|
43
|
+
# @alias_forming ||= machine.fetch_alias('forming').freeze
|
44
|
+
# end
|
45
|
+
|
46
|
+
def self.#{key}
|
47
|
+
@alias_#{key} ||= machine.fetch_alias('#{key}').freeze
|
48
|
+
end
|
49
|
+
RUBY
|
50
|
+
end
|
51
|
+
|
52
|
+
private_class_method def self.const_missing(name)
|
53
|
+
name_s = name.to_s
|
54
|
+
return super unless name_s.include?("__")
|
55
|
+
|
56
|
+
const_set name_s, name_s.split("__").map { |i| const_get(i) }.freeze
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EnumMachine
|
4
|
+
module BuildValueClass
|
5
|
+
def self.call(enum_values:, i18n_scope:, value_decorator:, machine: nil)
|
6
|
+
aliases = machine&.instance_variable_get(:@aliases) || {}
|
7
|
+
|
8
|
+
Class.new(String) do
|
9
|
+
include(value_decorator) if value_decorator
|
10
|
+
|
11
|
+
define_method(:machine) { machine } if machine
|
12
|
+
|
13
|
+
def inspect
|
14
|
+
"#<EnumMachine \"#{self}\">"
|
15
|
+
end
|
16
|
+
|
17
|
+
if machine&.transitions?
|
18
|
+
def possible_transitions
|
19
|
+
machine.possible_transitions(self)
|
20
|
+
end
|
21
|
+
|
22
|
+
def can?(enum_value)
|
23
|
+
possible_transitions.include?(enum_value)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
enum_values.each do |enum_value|
|
28
|
+
enum_name = enum_value.underscore
|
29
|
+
|
30
|
+
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
31
|
+
# def active?
|
32
|
+
# self == 'active'
|
33
|
+
# end
|
34
|
+
|
35
|
+
def #{enum_name}?
|
36
|
+
self == '#{enum_value}'
|
37
|
+
end
|
38
|
+
RUBY
|
39
|
+
|
40
|
+
if machine&.transitions?
|
41
|
+
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
42
|
+
# def can_active?
|
43
|
+
# possible_transitions.include?('canceled')
|
44
|
+
# end
|
45
|
+
|
46
|
+
def can_#{enum_name}?
|
47
|
+
possible_transitions.include?('#{enum_value}')
|
48
|
+
end
|
49
|
+
RUBY
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
aliases.each_key do |key|
|
54
|
+
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
55
|
+
# def forming?
|
56
|
+
# machine.fetch_alias('forming').include?(self)
|
57
|
+
# end
|
58
|
+
|
59
|
+
def #{key}?
|
60
|
+
machine.fetch_alias('#{key}').include?(self)
|
61
|
+
end
|
62
|
+
RUBY
|
63
|
+
end
|
64
|
+
|
65
|
+
if i18n_scope
|
66
|
+
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
67
|
+
# def human_name
|
68
|
+
# ::I18n.t(self, scope: "enums.product.state", default: self)
|
69
|
+
# end
|
70
|
+
|
71
|
+
def human_name
|
72
|
+
::I18n.t(self, scope: "enums.#{i18n_scope}", default: self)
|
73
|
+
end
|
74
|
+
RUBY
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -2,58 +2,116 @@
|
|
2
2
|
|
3
3
|
module EnumMachine
|
4
4
|
module DriverActiveRecord
|
5
|
-
|
6
|
-
def enum_machine(attr, enum_values, i18n_scope: nil, &block)
|
5
|
+
def enum_machine(attr, enum_values, i18n_scope: nil, value_decorator: nil, &block)
|
7
6
|
klass = self
|
8
7
|
|
9
|
-
attr_klass_name = attr.to_s.capitalize
|
10
|
-
read_method = "_read_attribute('#{attr}')"
|
11
8
|
i18n_scope ||= "#{klass.base_class.to_s.underscore}.#{attr}"
|
12
9
|
|
13
|
-
|
10
|
+
enum_const_name = attr.to_s.upcase
|
11
|
+
machine = Machine.new(enum_values, klass, enum_const_name, attr)
|
14
12
|
machine.instance_eval(&block) if block
|
15
|
-
aliases = machine.instance_variable_get(:@aliases)
|
16
13
|
|
17
|
-
|
18
|
-
|
14
|
+
value_class = BuildValueClass.call(enum_values: enum_values, i18n_scope: i18n_scope, machine: machine, value_decorator: value_decorator)
|
15
|
+
enum_class = BuildEnumClass.call(enum_values: enum_values, i18n_scope: i18n_scope, machine: machine, value_class: value_class)
|
19
16
|
|
17
|
+
value_class.extend(AttributePersistenceMethods[attr, enum_values])
|
18
|
+
|
19
|
+
# default_proc for working with custom values not defined in enum list but may exists in db
|
20
|
+
enum_class.value_attribute_mapping.default_proc =
|
21
|
+
proc do |hash, enum_value|
|
22
|
+
hash[enum_value] = value_class.new(enum_value).freeze
|
23
|
+
end
|
24
|
+
|
25
|
+
if machine.transitions?
|
20
26
|
klass.class_eval <<-RUBY, __FILE__, __LINE__ + 1 # rubocop:disable Style/DocumentDynamicEvalDefinition
|
21
|
-
|
22
|
-
|
23
|
-
|
27
|
+
before_save :__enum_machine_#{attr}_before_save
|
28
|
+
after_save :__enum_machine_#{attr}_after_save
|
29
|
+
|
30
|
+
def __enum_machine_#{attr}_before_save
|
31
|
+
if (attr_changes = changes['#{attr}']) && !@__enum_machine_#{attr}_skip_transitions
|
32
|
+
value_was, value_new = *attr_changes
|
33
|
+
self.class::#{enum_const_name}.machine.fetch_before_transitions(attr_changes).each do |block|
|
34
|
+
@__enum_machine_#{attr}_forced_value = value_was
|
35
|
+
instance_exec(self, value_was, value_new, &block)
|
36
|
+
ensure
|
37
|
+
@__enum_machine_#{attr}_forced_value = nil
|
38
|
+
end
|
24
39
|
end
|
25
40
|
end
|
26
|
-
|
27
|
-
|
28
|
-
|
41
|
+
|
42
|
+
def __enum_machine_#{attr}_after_save
|
43
|
+
if (attr_changes = previous_changes['#{attr}']) && !@__enum_machine_#{attr}_skip_transitions
|
44
|
+
self.class::#{enum_const_name}.machine.fetch_after_transitions(attr_changes).each { |block| instance_exec(self, *attr_changes, &block) }
|
29
45
|
end
|
30
46
|
end
|
31
47
|
RUBY
|
32
48
|
end
|
33
49
|
|
34
|
-
|
35
|
-
|
36
|
-
attribute_klass =
|
37
|
-
BuildAttribute.call(
|
38
|
-
attr: attr,
|
39
|
-
read_method: read_method,
|
40
|
-
enum_values: enum_values,
|
41
|
-
i18n_scope: i18n_scope,
|
42
|
-
machine: machine,
|
43
|
-
aliases_keys: aliases.keys,
|
44
|
-
)
|
45
|
-
klass.class_variable_set("@@#{attr}_attribute", attribute_klass)
|
46
|
-
|
47
|
-
klass.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
50
|
+
define_methods = Module.new
|
51
|
+
define_methods.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
48
52
|
# def state
|
49
|
-
# @
|
53
|
+
# enum_value = @__enum_machine_state_forced_value || super()
|
54
|
+
# return unless enum_value
|
55
|
+
#
|
56
|
+
# unless @__enum_value_state == enum_value
|
57
|
+
# @__enum_value_state = self.class::STATE.value_attribute_mapping[enum_value].dup
|
58
|
+
# @__enum_value_state.parent = self
|
59
|
+
# @__enum_value_state.freeze
|
60
|
+
# end
|
61
|
+
#
|
62
|
+
# @__enum_value_state
|
63
|
+
# end
|
64
|
+
#
|
65
|
+
# def skip_state_transitions
|
66
|
+
# @__enum_machine_state_skip_transitions = true
|
67
|
+
# yield
|
68
|
+
# ensure
|
69
|
+
# @__enum_machine_state_skip_transitions = false
|
70
|
+
# end
|
71
|
+
#
|
72
|
+
# def initialize_dup(other)
|
73
|
+
# @__enum_value_state = nil
|
74
|
+
# super
|
50
75
|
# end
|
51
76
|
|
52
77
|
def #{attr}
|
53
|
-
|
78
|
+
enum_value = @__enum_machine_#{attr}_forced_value || super()
|
79
|
+
return unless enum_value
|
80
|
+
|
81
|
+
unless @__enum_value_#{attr} == enum_value
|
82
|
+
@__enum_value_#{attr} = self.class::#{enum_const_name}.value_attribute_mapping[enum_value].dup
|
83
|
+
@__enum_value_#{attr}.parent = self
|
84
|
+
@__enum_value_#{attr}.freeze
|
85
|
+
end
|
86
|
+
|
87
|
+
@__enum_value_#{attr}
|
88
|
+
end
|
89
|
+
|
90
|
+
def skip_#{attr}_transitions
|
91
|
+
@__enum_machine_#{attr}_skip_transitions = true
|
92
|
+
yield
|
93
|
+
ensure
|
94
|
+
@__enum_machine_#{attr}_skip_transitions = false
|
95
|
+
end
|
96
|
+
|
97
|
+
def initialize_dup(other)
|
98
|
+
@__enum_value_#{attr} = nil
|
99
|
+
super
|
54
100
|
end
|
55
101
|
RUBY
|
56
|
-
end
|
57
102
|
|
103
|
+
enum_decorator =
|
104
|
+
Module.new do
|
105
|
+
define_singleton_method(:included) do |decorating_class|
|
106
|
+
decorating_class.prepend define_methods
|
107
|
+
decorating_class.const_set enum_const_name, enum_class
|
108
|
+
end
|
109
|
+
end
|
110
|
+
enum_class.define_singleton_method(:enum_decorator) { enum_decorator }
|
111
|
+
|
112
|
+
klass.include(enum_decorator)
|
113
|
+
|
114
|
+
enum_decorator
|
115
|
+
end
|
58
116
|
end
|
59
117
|
end
|
@@ -2,7 +2,6 @@
|
|
2
2
|
|
3
3
|
module EnumMachine
|
4
4
|
module DriverSimpleClass
|
5
|
-
|
6
5
|
# include EnumMachine[
|
7
6
|
# state: { enum: %w[choice in_delivery], i18n_scope: 'line_item.state' },
|
8
7
|
# color: { enum: %w[red green yellow] },
|
@@ -12,41 +11,42 @@ module EnumMachine
|
|
12
11
|
Module.new do
|
13
12
|
define_singleton_method(:included) do |klass|
|
14
13
|
args.each do |attr, params|
|
15
|
-
enum_values
|
16
|
-
i18n_scope
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
14
|
+
enum_values = params.fetch(:enum)
|
15
|
+
i18n_scope = params.fetch(:i18n_scope, nil)
|
16
|
+
value_decorator = params.fetch(:value_decorator, nil)
|
17
|
+
|
18
|
+
if defined?(ActiveRecord) && klass <= ActiveRecord::Base
|
19
|
+
klass.enum_machine(attr, enum_values, i18n_scope: i18n_scope)
|
20
|
+
else
|
21
|
+
enum_const_name = attr.to_s.upcase
|
22
|
+
value_class = BuildValueClass.call(enum_values: enum_values, i18n_scope: i18n_scope, value_decorator: value_decorator)
|
23
|
+
enum_class = BuildEnumClass.call(enum_values: enum_values, i18n_scope: i18n_scope, value_class: value_class)
|
24
|
+
|
25
|
+
define_methods =
|
26
|
+
Module.new do
|
27
|
+
define_method(attr) do
|
28
|
+
enum_value = super()
|
29
|
+
return unless enum_value
|
30
|
+
|
31
|
+
enum_class.value_attribute_mapping.fetch(enum_value)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
enum_decorator =
|
36
|
+
Module.new do
|
37
|
+
define_singleton_method(:included) do |decorating_class|
|
38
|
+
decorating_class.prepend define_methods
|
39
|
+
decorating_class.const_set enum_const_name, enum_class
|
40
|
+
end
|
41
|
+
end
|
42
|
+
enum_class.define_singleton_method(:enum_decorator) { enum_decorator }
|
43
|
+
|
44
|
+
klass.include(enum_decorator)
|
45
|
+
enum_decorator
|
46
|
+
end
|
46
47
|
end
|
47
48
|
end
|
48
49
|
end
|
49
50
|
end
|
50
|
-
|
51
51
|
end
|
52
52
|
end
|
data/lib/enum_machine/machine.rb
CHANGED
@@ -2,11 +2,13 @@
|
|
2
2
|
|
3
3
|
module EnumMachine
|
4
4
|
class Machine
|
5
|
+
attr_reader :enum_values, :base_klass, :enum_const_name, :attr_name
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
def initialize(enum_values)
|
7
|
+
def initialize(enum_values, base_klass = nil, enum_const_name = nil, attr_name = nil) # rubocop:disable Gp/OptArgParameters
|
9
8
|
@enum_values = enum_values
|
9
|
+
@base_klass = base_klass
|
10
|
+
@enum_const_name = enum_const_name
|
11
|
+
@attr_name = attr_name
|
10
12
|
@transitions = {}
|
11
13
|
@before_transition = {}
|
12
14
|
@after_transition = {}
|
@@ -18,8 +20,8 @@ module EnumMachine
|
|
18
20
|
def transitions(from__to_hash)
|
19
21
|
validate_state!(from__to_hash)
|
20
22
|
|
21
|
-
from__to_hash.each do |from_arr,
|
22
|
-
array_wrap(from_arr).each do |from|
|
23
|
+
from__to_hash.each do |from_arr, to_arr|
|
24
|
+
array_wrap(from_arr).product(array_wrap(to_arr)).each do |from, to|
|
23
25
|
@transitions[from] ||= []
|
24
26
|
@transitions[from] << to
|
25
27
|
end
|
@@ -32,9 +34,7 @@ module EnumMachine
|
|
32
34
|
def before_transition(from__to_hash, &block)
|
33
35
|
validate_state!(from__to_hash)
|
34
36
|
|
35
|
-
|
36
|
-
array_wrap(from).product(Array(to)).each do |from_pair_to|
|
37
|
-
valid_transition!(from_pair_to)
|
37
|
+
filter_transitions(from__to_hash).each do |from_pair_to|
|
38
38
|
@before_transition[from_pair_to] ||= []
|
39
39
|
@before_transition[from_pair_to] << block
|
40
40
|
end
|
@@ -46,30 +46,36 @@ module EnumMachine
|
|
46
46
|
def after_transition(from__to_hash, &block)
|
47
47
|
validate_state!(from__to_hash)
|
48
48
|
|
49
|
-
|
50
|
-
array_wrap(from).product(Array(to)).each do |from_pair_to|
|
51
|
-
valid_transition!(from_pair_to)
|
49
|
+
filter_transitions(from__to_hash).each do |from_pair_to|
|
52
50
|
@after_transition[from_pair_to] ||= []
|
53
51
|
@after_transition[from_pair_to] << block
|
54
52
|
end
|
55
53
|
end
|
56
54
|
|
57
55
|
# public api
|
58
|
-
def
|
59
|
-
enum_values
|
56
|
+
def any
|
57
|
+
@any ||= AnyEnumValues.new(enum_values + [nil])
|
60
58
|
end
|
61
59
|
|
62
60
|
def aliases(hash)
|
63
61
|
@aliases = hash
|
64
62
|
end
|
65
63
|
|
64
|
+
def fetch_aliases
|
65
|
+
@aliases
|
66
|
+
end
|
67
|
+
|
66
68
|
def transitions?
|
67
69
|
@transitions.present?
|
68
70
|
end
|
69
71
|
|
72
|
+
def fetch_transitions
|
73
|
+
@transitions
|
74
|
+
end
|
75
|
+
|
70
76
|
# internal api
|
71
77
|
def fetch_before_transitions(from__to)
|
72
|
-
|
78
|
+
validate_transition!(from__to)
|
73
79
|
@before_transition.fetch(from__to, [])
|
74
80
|
end
|
75
81
|
|
@@ -78,6 +84,11 @@ module EnumMachine
|
|
78
84
|
@after_transition.fetch(from__to, [])
|
79
85
|
end
|
80
86
|
|
87
|
+
# internal api
|
88
|
+
def fetch_alias(alias_key)
|
89
|
+
array_wrap(@aliases.fetch(alias_key))
|
90
|
+
end
|
91
|
+
|
81
92
|
# internal api
|
82
93
|
def possible_transitions(from)
|
83
94
|
@transitions.fetch(from, [])
|
@@ -89,10 +100,25 @@ module EnumMachine
|
|
89
100
|
end
|
90
101
|
end
|
91
102
|
|
92
|
-
private def
|
93
|
-
|
94
|
-
|
95
|
-
|
103
|
+
private def filter_transitions(from__to_hash)
|
104
|
+
from_arr, to_arr = from__to_hash.to_a.first
|
105
|
+
is_any_enum_values = from_arr.is_a?(AnyEnumValues) || to_arr.is_a?(AnyEnumValues)
|
106
|
+
|
107
|
+
array_wrap(from_arr).product(array_wrap(to_arr)).filter do |from__to|
|
108
|
+
if is_any_enum_values
|
109
|
+
from, to = from__to
|
110
|
+
possible_transitions(from).include?(to)
|
111
|
+
else
|
112
|
+
validate_transition!(from__to)
|
113
|
+
true
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
private def validate_transition!(from__to)
|
119
|
+
from, to = from__to
|
120
|
+
unless possible_transitions(from).include?(to)
|
121
|
+
raise EnumMachine::InvalidTransition.new(self, from, to)
|
96
122
|
end
|
97
123
|
end
|
98
124
|
|
@@ -104,5 +130,7 @@ module EnumMachine
|
|
104
130
|
end
|
105
131
|
end
|
106
132
|
|
133
|
+
class AnyEnumValues < Array
|
134
|
+
end
|
107
135
|
end
|
108
136
|
end
|
data/lib/enum_machine/version.rb
CHANGED
data/lib/enum_machine.rb
CHANGED
@@ -1,23 +1,37 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
4
|
-
require_relative
|
5
|
-
require_relative
|
6
|
-
require_relative
|
7
|
-
require_relative
|
8
|
-
|
3
|
+
require_relative "enum_machine/version"
|
4
|
+
require_relative "enum_machine/driver_simple_class"
|
5
|
+
require_relative "enum_machine/build_value_class"
|
6
|
+
require_relative "enum_machine/attribute_persistence_methods"
|
7
|
+
require_relative "enum_machine/build_enum_class"
|
8
|
+
require_relative "enum_machine/machine"
|
9
|
+
require "active_support"
|
9
10
|
|
10
11
|
module EnumMachine
|
11
|
-
|
12
12
|
class Error < StandardError; end
|
13
13
|
|
14
|
+
class InvalidTransition < Error
|
15
|
+
attr_reader :from, :to, :enum_const
|
16
|
+
|
17
|
+
def initialize(machine, from, to)
|
18
|
+
@from = from
|
19
|
+
@to = to
|
20
|
+
@enum_const =
|
21
|
+
begin
|
22
|
+
machine.base_klass.const_get(machine.enum_const_name)
|
23
|
+
rescue NameError # rubocop:disable Lint/SuppressedException
|
24
|
+
end
|
25
|
+
super("Transition #{from.inspect} => #{to.inspect} not defined in enum_machine :#{machine.attr_name}")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
14
29
|
def self.[](args)
|
15
30
|
DriverSimpleClass.call(args)
|
16
31
|
end
|
17
|
-
|
18
32
|
end
|
19
33
|
|
20
34
|
ActiveSupport.on_load(:active_record) do
|
21
|
-
require_relative
|
22
|
-
|
35
|
+
require_relative "enum_machine/driver_active_record"
|
36
|
+
ActiveSupport.on_load(:active_record) { extend EnumMachine::DriverActiveRecord }
|
23
37
|
end
|
metadata
CHANGED
@@ -1,58 +1,59 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: enum_machine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ermolaev Andrey
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-11-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activerecord
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: activesupport
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '0'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
55
|
-
description:
|
54
|
+
version: '0'
|
55
|
+
description: Enum machine is a library for defining enums and setting state machines
|
56
|
+
for attributes in ActiveRecord models and plain Ruby classes.
|
56
57
|
email:
|
57
58
|
- andruhafirst@yandex.ru
|
58
59
|
executables: []
|
@@ -68,9 +69,11 @@ files:
|
|
68
69
|
- Rakefile
|
69
70
|
- bin/console
|
70
71
|
- bin/setup
|
72
|
+
- docs/MIGRATING_FROM_RAILS_STRING_ENUM.ru.md
|
71
73
|
- lib/enum_machine.rb
|
72
|
-
- lib/enum_machine/
|
73
|
-
- lib/enum_machine/
|
74
|
+
- lib/enum_machine/attribute_persistence_methods.rb
|
75
|
+
- lib/enum_machine/build_enum_class.rb
|
76
|
+
- lib/enum_machine/build_value_class.rb
|
74
77
|
- lib/enum_machine/driver_active_record.rb
|
75
78
|
- lib/enum_machine/driver_simple_class.rb
|
76
79
|
- lib/enum_machine/machine.rb
|
@@ -83,7 +86,7 @@ metadata:
|
|
83
86
|
homepage_uri: https://github.com/corp-gp/enum_machine
|
84
87
|
source_code_uri: https://github.com/corp-gp/enum_machine
|
85
88
|
rubygems_mfa_required: 'true'
|
86
|
-
post_install_message:
|
89
|
+
post_install_message:
|
87
90
|
rdoc_options: []
|
88
91
|
require_paths:
|
89
92
|
- lib
|
@@ -91,15 +94,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
91
94
|
requirements:
|
92
95
|
- - ">="
|
93
96
|
- !ruby/object:Gem::Version
|
94
|
-
version:
|
97
|
+
version: 3.0.0
|
95
98
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
99
|
requirements:
|
97
100
|
- - ">="
|
98
101
|
- !ruby/object:Gem::Version
|
99
102
|
version: '0'
|
100
103
|
requirements: []
|
101
|
-
rubygems_version: 3.
|
102
|
-
signing_key:
|
104
|
+
rubygems_version: 3.3.17
|
105
|
+
signing_key:
|
103
106
|
specification_version: 4
|
104
|
-
summary: state machine
|
107
|
+
summary: fast and siple usage state machine in your app
|
105
108
|
test_files: []
|