File: shared_enums.rb

package info (click to toggle)
ruby-enumerize 2.8.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 432 kB
  • sloc: ruby: 3,712; makefile: 6
file content (43 lines) | stat: -rw-r--r-- 1,020 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# frozen_string_literal: true

require 'active_record'
require 'sequel'

module EnumerizeExtention
  def self.included(base)
    case
    when base < ActiveRecord::Base
      base.extend Enumerize
    when base < Sequel::Model
      base.plugin :enumerize
    end
  end
end

module SkipValidationsEnum
  def self.included(base)
    base.include EnumerizeExtention
    base.enumerize :foo, :in => [:bar, :baz], :skip_validations => true
  end
end

module DoNotSkipValidationsEnum
  def self.included(base)
    base.include EnumerizeExtention
    base.enumerize :foo, :in => [:bar, :baz], :skip_validations => false
  end
end

module SkipValidationsLambdaEnum
  def self.included(base)
    base.include EnumerizeExtention
    base.enumerize :foo, :in => [:bar, :baz], :skip_validations => lambda { true }
  end
end

module SkipValidationsLambdaWithParamEnum
  def self.included(base)
    base.include EnumerizeExtention
    base.enumerize :foo, :in => [:bar, :baz], :skip_validations => lambda { |record| true }
  end
end