Method: Effective::Attribute#initialize

Defined in:
app/models/effective/attribute.rb

#initialize(obj, type = nil, klass: nil) ⇒ Attribute

We also use this class to do value parsing in Datatables. In that case it will be initialized with just a ‘name’



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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'app/models/effective/attribute.rb', line 19

def initialize(obj, type = nil, klass: nil)
  @klass = klass

  if obj.present? && type.present?
    @name = obj.to_s
    @type = type.to_sym
  end

  @type ||= (
    case obj
    when :boolean     ; :boolean
    when :config      ; :config
    when :currency    ; :currency
    when :date        ; :date
    when :datetime    ; :datetime
    when :decimal     ; :decimal
    when :duration    ; :duration
    when :email       ; :email
    when :integer     ; :integer
    when :percent     ; :percent
    when :percentage  ; :percent
    when :phone       ; :phone
    when :price       ; :price
    when :nil         ; :nil
    when :resource    ; :resource
    when :select      ; :string
    when :radios      ; :string
    when :string      ; :string
    when :text        ; :string
    when :time        ; :time
    when :uuid        ; :uuid
    when :url         ; :url
    when FalseClass   ; :boolean
    when (defined?(Integer) ? Integer : Fixnum) ; :integer
    when Float        ; :decimal
    when NilClass     ; :nil
    when String       ; :string
    when TrueClass    ; :boolean
    when ActiveSupport::TimeWithZone  ; :datetime
    when Date                         ; :date
    when ActiveRecord::Base           ; :resource
    when :belongs_to                  ; :belongs_to
    when :belongs_to_polymorphic      ; :belongs_to_polymorphic
    when :has_many                    ; :has_many
    when :has_and_belongs_to_many     ; :has_and_belongs_to_many
    when :has_one                     ; :has_one
    when :effective_addresses         ; :effective_addresses
    when :effective_obfuscation       ; :effective_obfuscation
    when :effective_roles             ; :effective_roles
    when :active_storage              ; :active_storage
    else
      raise "unsupported type for #{obj}"
    end
  )
end