Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/enum_machine/build_enum_class.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
1 change: 1 addition & 0 deletions spec/enum_machine/active_record_enum_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions spec/enum_machine/driver_simple_class_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down