Sha256: 6bf4383bb7fb3be9270096dfd65a80ed337d5cafbe0b0ff721cc029e3bfd0e77

Contents?: true

Size: 809 Bytes

Versions: 13

Compression:

Stored size: 809 Bytes

Contents

require 'rubygems'
require 'active_record'
require 'ar-enums'

ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
load(File.dirname(__FILE__) + "/../spec/schema.rb")

class TrafficLight < ActiveRecord::Base
  enum :state, %w[red green yellow]
end

tl = TrafficLight.new(:state => :green)
p tl.state      # => #<TrafficLight::State @name="green", @id=2>
p tl.state_id   # => 2    
p TrafficLight.states.map(&:to_s)

# class TrafficLight < ActiveRecord::Base
#   enum :state, [
#     { :name => :red, :stop_traffic => true, :rgb => 0xF00 },
#     { :name => :green, :stop_traffic => false, :rgb => 0x0F0 }
#   ]
# end
# 
# tl = TrafficLight.new(:state => :green)
# p tl.state_id       # => 2    
# p tl.state.stop_traffic   # => false
# p tl.state.rgb            # => 0x0F0

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
ar-enums-2.0.1 examples/internal_enums.rb
ar-enums-2.0.0 examples/internal_enums.rb
ar-enums-1.0.0 examples/internal_enums.rb
ar-enums-0.3.9 examples/internal_enums.rb
ar-enums-0.3.8 examples/internal_enums.rb
ar-enums-0.3.7 examples/internal_enums.rb
ar-enums-0.3.6 examples/internal_enums.rb
ar-enums-0.3.5 examples/internal_enums.rb
ar-enums-0.3.4 examples/internal_enums.rb
ar-enums-0.3.3 examples/internal_enums.rb
ar-enums-0.3.2 examples/internal_enums.rb
ar-enums-0.3.1 examples/internal_enums.rb
ar-enums-0.3.0 examples/internal_enums.rb