Module: Traits::Attribute::Type

Included in:
Traits::Attribute
Defined in:
lib/traits/attribute/type.rb

Instance Method Summary collapse

Instance Method Details

#active_record_timestamp?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/traits/attribute/type.rb', line 51

def active_record_timestamp?
  datetime? && (name == :created_at || name == :updated_at || name == :deleted_at)
end

#big?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/traits/attribute/type.rb', line 23

def big?
  text? || binary?
end

#binary?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/traits/attribute/type.rb', line 19

def binary?
  type == :binary
end

#datetime?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/traits/attribute/type.rb', line 47

def datetime?
  type == :datetime
end

#decimal?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/traits/attribute/type.rb', line 35

def decimal?
  type == :decimal
end

#float?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/traits/attribute/type.rb', line 31

def float?
  type == :float
end

#integer?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/traits/attribute/type.rb', line 27

def integer?
  type == :integer
end

#number?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/traits/attribute/type.rb', line 43

def number?
  integer? || float? || decimal?
end

#real?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/traits/attribute/type.rb', line 39

def real?
  float? || decimal?
end

#string?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/traits/attribute/type.rb', line 11

def string?
  type == :string
end

#text?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/traits/attribute/type.rb', line 15

def text?
  type == :text
end

#to_hashObject



55
56
57
58
59
# File 'lib/traits/attribute/type.rb', line 55

def to_hash
  super.merge!(
    type: type
  )
end

#typeObject



7
8
9
# File 'lib/traits/attribute/type.rb', line 7

def type
  @type ||= column_definition.type.to_sym
end