Skip to content

Commit

Permalink
feat: add inspect
Browse files Browse the repository at this point in the history
  • Loading branch information
hatsu38 authored and flavorjones committed Sep 4, 2024
1 parent 81a1d8c commit 3a7a17f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/enum/enum.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def enum(columns)
columns.each do |column, values|
values = values.zip(values.map(&:to_s)).to_h if values.is_a?(Array)
values.each do |method, value|
method_definitions << "def #{method}?; #{column} == '#{value}'; end"
method_definitions << "def #{method}?; #{column} == #{value.inspect}; end"
end
end
class_eval(method_definitions.uniq.join(";"))
Expand Down
8 changes: 4 additions & 4 deletions spec/enum/enum_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,20 +109,20 @@ class Neighborhood < ActiveHash::Base
expect(Article::ARTICLE_3.archived?).to be_truthy
end

it "defines a predicate method for each value in the enum" do
it "multi type data (ex: string, integer and symbol) enum" do
NotifyType = Class.new(ActiveHash::Base) do
include ActiveHash::Enum

self.data = [
{ name: 'Like', action: 'LIKE'},
{ name: 'Comment', action: 'COMMENT'},
{ name: 'Follow', action: 'FOLLOW'},
{ name: 'Comment', action: 1},
{ name: 'Follow', action: :FOLLOW},
{ name: 'Mention', action: 'MENTION'}
]

enum_accessor :name

enum action: { like: 'LIKE', comment: 'COMMENT', follow: 'FOLLOW', mention: 'MENTION' }
enum action: { like: 'LIKE', comment: 1, follow: :FOLLOW, mention: 'MENTION' }
end

expect(NotifyType::LIKE.like?).to be_truthy
Expand Down

0 comments on commit 3a7a17f

Please sign in to comment.