Module: Marty::PgEnum

Included in:
EnumEventOperation, EnumPromiseType, Notifications::EventType, PostingType, RoleType
Defined in:
app/models/marty/pg_enum.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/models/marty/pg_enum.rb', line 12

def self.extended(base)
  base.class_eval do
    extend ::Delorean::Functions unless respond_to?(:delorean_fn)

    delorean_fn :get_all do |_pt = nil|
      values.map(&:to_s)
    end

    delorean_fn :[] do |i0, i1 = nil|
      super(i0, i1)
    end

    delorean_fn :lookup do |i0, i1 = nil|
      send(:[], i0, i1)
    end

    delorean_fn :find_by_name do |i0, i1 = nil|
      send(:[], i0, i1)
    end
  end
end

Instance Method Details

#[](i0, i1 = nil) ⇒ Object



2
3
4
5
6
7
8
9
10
# File 'app/models/marty/pg_enum.rb', line 2

def [](i0, i1 = nil)
  # if i1 is provided, then i0 is a pt and we ignore it.
  index = (i1 || i0).to_s

  raise "no such #{name}: '#{index}'" unless
  values.include?(index)

  index
end

#_pg_enum?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'app/models/marty/pg_enum.rb', line 41

def _pg_enum?
  true
end

#seedObject



38
39
# File 'app/models/marty/pg_enum.rb', line 38

def seed
end

#valuesObject



34
35
36
# File 'app/models/marty/pg_enum.rb', line 34

def values
  self::VALUES
end