Class: Bagman::SimpleColumn

Inherits:
ActiveRecord::ConnectionAdapters::Column
  • Object
show all
Defined in:
lib/bagman/simple_column.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, role, type, options = {}) ⇒ SimpleColumn

Returns a new instance of SimpleColumn.



8
9
10
# File 'lib/bagman/simple_column.rb', line 8

def initialize(name, role, type, options={})
  @name, @role, @type, @options = name, role, type, options
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/bagman/simple_column.rb', line 6

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/bagman/simple_column.rb', line 6

def options
  @options
end

#typeObject (readonly)

Returns the value of attribute type.



6
7
8
# File 'lib/bagman/simple_column.rb', line 6

def type
  @type
end

Class Method Details

.dd_mm_yyyy_to_date(string) ⇒ Object



38
39
40
# File 'lib/bagman/simple_column.rb', line 38

def self.dd_mm_yyyy_to_date(string)
  Date.strptime(string, "%d/%m/%Y") rescue nil
end

.dd_mm_yyyy_to_time(string) ⇒ Object



46
47
48
# File 'lib/bagman/simple_column.rb', line 46

def self.dd_mm_yyyy_to_time(string)
  DateTime.strptime(string, "%d/%m/%Y") rescue nil
end

.string_to_date(string) ⇒ Object



34
35
36
# File 'lib/bagman/simple_column.rb', line 34

def self.string_to_date(string)
  dd_mm_yyyy_to_date(string) || super
end

.string_to_time(string) ⇒ Object



42
43
44
# File 'lib/bagman/simple_column.rb', line 42

def self.string_to_time(string)
  dd_mm_yyyy_to_time(string) || super
end

Instance Method Details

#index?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/bagman/simple_column.rb', line 30

def index?
  !! index_name
end

#index_nameObject



21
22
23
24
25
26
27
28
# File 'lib/bagman/simple_column.rb', line 21

def index_name
  case options[:index]
  when TrueClass
    "index_#{name}"
  when String,Symbol
    options[:index]
  end
end

#type_cast(value) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/bagman/simple_column.rb', line 12

def type_cast(value)
  case type
  when Class
    type.new(value)
  else
    super
  end
end