Class: ActiveFacts::RMap::Column

Inherits:
Object
  • Object
show all
Defined in:
lib/activefacts/generators/rails/models.rb,
lib/activefacts/generators/traits/rails.rb,
lib/activefacts/generators/transform/surrogate.rb

Instance Method Summary collapse

Instance Method Details

#is_auto_timestampObject



235
236
237
238
239
240
241
242
# File 'lib/activefacts/generators/rails/models.rb', line 235

def is_auto_timestamp
  case name('_')
  when /\A(created|updated)_(at|on)\Z/i
    true
  else
    false
  end
end

#is_injected_surrogateObject



184
185
186
187
# File 'lib/activefacts/generators/transform/surrogate.rb', line 184

def is_injected_surrogate
  references.size == 1 and
    references[0].from_role == references[0].from.injected_surrogate_role
end

#rails_nameObject



36
37
38
# File 'lib/activefacts/generators/traits/rails.rb', line 36

def rails_name
  RMap::rails_singular_name(name('_'))
end

#rails_typeObject



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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/activefacts/generators/traits/rails.rb', line 40

def rails_type
  type_name, params, constraints = *type()
  rails_type = case type_name
    when /^Auto ?Counter$/i
      'serial'        # REVISIT: Need to detect surrogate ID fields and handle them correctly

    when /^[Ug]uid$/i
      'uuid'

    when /^Unsigned ?Integer$/i,
      /^Integer$/i,
      /^Signed ?Integer$/i,
      /^Unsigned ?Small ?Integer$/i,
      /^Signed ?Small ?Integer$/i,
      /^Unsigned ?Tiny ?Integer$/i
      length = nil
      'integer'

    when /^Decimal$/i
      'decimal'

    when /^Float$/i, /^Double$/i, /^Real$/i
      'float'

    when /^Fixed ?Length ?Text$/i, /^Char$/i
      'string'
    when /^Variable ?Length ?Text$/i, /^String$/i
      'string'
    when /^Large ?Length ?Text$/i, /^Text$/i
      'text'

    when /^Date ?And ?Time$/i, /^Date ?Time$/i
      'datetime'
    when /^Date$/i
      'datetime'
    when /^Time$/i
      'time'
    when /^Auto ?Time ?Stamp$/i
      'timestamp'

    when /^Money$/i
      'decimal'
    when /^Picture ?Raw ?Data$/i, /^Image$/i, /^Variable ?Length ?Raw ?Data$/i, /^Blob$/i
      'binary'
    when /^BIT$/i, /^Boolean$/i
      'boolean'
    else
      type_name # raise "ActiveRecord type unknown for standard type #{type}"
    end
  [rails_type, params[:length]]
end