Skip to content

Releases: corp-gp/enum_machine

v2.1.0

16 Dec 14:10

Choose a tag to compare

perf: build class, better show_source (#43)
feat: add question predicate method for check in severals values (#44)

class TestClass
  attr_accessor :state

  def initialize(state)
    @state = state
  end

  include EnumMachine[state: { enum: %w[choice in_delivery lost] }]
end

item = TestClass.new("choice")
item.state.choice__in_delivery? # => true
item.state.lost__in_delivery? # => false 

v2.0.0

28 Nov 04:43

Choose a tag to compare

Added

  • value_decorator option
# Value classes nested from base class
module ColorDecorator
  def hex
    case self
    when Product::COLOR::RED then "#ff0000"
    when Product::COLOR::GREEN then "#00ff00"
    end
  end
end

class Product
  attr_accessor :color

  include EnumMachine[color: { enum: %w[red green], value_decorator: ColorDecorator }]
end

product = Product.new
product.color = "red"
product.color.hex # => "#ff0000"

Breaking changes

  • #decorator_module method renamed to #enum_decorator