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/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| 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