Sha256: fa9ffad75bad13b29c696217108b7066b24ba0d416137bca4b71b020f933b839

Contents?: true

Size: 682 Bytes

Versions: 12

Compression:

Stored size: 682 Bytes

Contents

$LOAD_PATH.unshift '../lib'
require 'memory_record'

require 'active_record'

ActiveRecord::VERSION::STRING   # => "5.1.4"
ActiveRecord::Migration.verbose = false
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')

ActiveRecord::Schema.define do
  create_table :users do |t|
    t.integer :gender_key
  end
end

class GenderInfo
  include MemoryRecord
  memory_record [
    {key: :male,   name: '♂'},
    {key: :female, name: '♀'},
  ]
end

class User < ActiveRecord::Base
  enum gender_key: GenderInfo.keys

  def gender_info
    GenderInfo[gender_key]
  end
end

user = User.create!(gender_key: :male)
user.gender_info.name           # => "♂"

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
memory_record-0.0.20 examples/0230_with_use_activerecord_enum.rb
memory_record-0.0.19 examples/0230_with_use_activerecord_enum.rb
memory_record-0.0.18 examples/0230_with_use_activerecord_enum.rb
memory_record-0.0.17 examples/0230_with_use_activerecord_enum.rb
memory_record-0.0.15 examples/0230_with_use_activerecord_enum.rb
memory_record-0.0.14 examples/0230_with_use_activerecord_enum.rb
memory_record-0.0.13 examples/0230_with_use_activerecord_enum.rb
memory_record-0.0.12 examples/0230_with_use_activerecord_enum.rb
memory_record-0.0.11 examples/0230_with_use_activerecord_enum.rb
memory_record-0.0.10 examples/0230_with_use_activerecord_enum.rb
memory_record-0.0.9 examples/0230_with_use_activerecord_enum.rb
memory_record-0.0.8 examples/0230_with_use_activerecord_enum.rb