From 49819f5a2dd13fee212a2614c89184cc7bed89f5 Mon Sep 17 00:00:00 2001 From: Sergei Malykh Date: Thu, 1 Jan 2026 10:58:27 +0300 Subject: [PATCH 1/2] improve value constants with value methods --- lib/enum_machine/build_enum_class.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/enum_machine/build_enum_class.rb b/lib/enum_machine/build_enum_class.rb index 87d30d6..416efa0 100644 --- a/lib/enum_machine/build_enum_class.rb +++ b/lib/enum_machine/build_enum_class.rb @@ -36,7 +36,7 @@ def self.human_name_for(name) end enum_values.each do |enum_value| - const_set enum_value.underscore.upcase, enum_value.to_s.freeze + const_set enum_value.underscore.upcase, value_class.new(enum_value).freeze end aliases.each_key do |key| From 70bcdbf01c436f298e08ea8f0dc44ab6d65afe64 Mon Sep 17 00:00:00 2001 From: Sergei Malykh Date: Thu, 1 Jan 2026 11:07:08 +0300 Subject: [PATCH 2/2] add specs & docs --- README.md | 2 ++ spec/enum_machine/active_record_enum_spec.rb | 1 + spec/enum_machine/driver_simple_class_spec.rb | 3 +++ 3 files changed, 6 insertions(+) diff --git a/README.md b/README.md index eca001f..f6dc8cd 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,8 @@ end Product::COLOR.values # => ["red", "green"] Product::COLOR::RED # => "red" +Product::COLOR::RED.red? # => true +Product::COLOR::RED.human_name # => "Красный" Product::COLOR::RED__GREEN # => ["red", "green"] Product::COLOR["red"].red? # => true diff --git a/spec/enum_machine/active_record_enum_spec.rb b/spec/enum_machine/active_record_enum_spec.rb index 4e893e5..ff62466 100644 --- a/spec/enum_machine/active_record_enum_spec.rb +++ b/spec/enum_machine/active_record_enum_spec.rb @@ -41,6 +41,7 @@ m = model.new(color: "red") expect(m.color.human_name).to eq "Красный" expect(model::COLOR.human_name_for("red")).to eq "Красный" + expect(model::COLOR::RED.human_name).to eq "Красный" end context "when enum in CamelCase" do diff --git a/spec/enum_machine/driver_simple_class_spec.rb b/spec/enum_machine/driver_simple_class_spec.rb index f2e8311..d394094 100644 --- a/spec/enum_machine/driver_simple_class_spec.rb +++ b/spec/enum_machine/driver_simple_class_spec.rb @@ -36,6 +36,9 @@ def initialize(state) it { expect { item.state.last__in_delivery? }.to raise_error(NoMethodError) } it { expect(item.state).to eq "choice" } it { expect(item.state.frozen?).to be true } + it { expect(TestClass::STATE::IN_DELIVERY.in_delivery?).to be true } + it { expect(TestClass::STATE::IN_DELIVERY.choice?).to be false } + it { expect(TestClass::STATE::IN_DELIVERY.frozen?).to be true } describe "module" do it "returns state string" do