~michaelforrest/use-case-mapper/trunk

« back to all changes in this revision

Viewing changes to vendor/rails/railties/lib/rails_generator/generated_attribute.rb

  • Committer: Richard Lee (Canonical)
  • Date: 2010-10-15 15:17:58 UTC
  • mfrom: (190.1.3 use-case-mapper)
  • Revision ID: richard.lee@canonical.com-20101015151758-wcvmfxrexsongf9d
Merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
require 'optparse'
2
 
 
3
 
module Rails
4
 
  module Generator
5
 
    class GeneratedAttribute
6
 
      attr_accessor :name, :type, :column
7
 
 
8
 
      def initialize(name, type)
9
 
        @name, @type = name, type.to_sym
10
 
        @column = ActiveRecord::ConnectionAdapters::Column.new(name, nil, @type)
11
 
      end
12
 
 
13
 
      def field_type
14
 
        @field_type ||= case type
15
 
          when :integer, :float, :decimal   then :text_field
16
 
          when :datetime, :timestamp, :time then :datetime_select
17
 
          when :date                        then :date_select
18
 
          when :string                      then :text_field
19
 
          when :text                        then :text_area
20
 
          when :boolean                     then :check_box
21
 
          else
22
 
            :text_field
23
 
        end      
24
 
      end
25
 
 
26
 
      def default
27
 
        @default ||= case type
28
 
          when :integer                     then 1
29
 
          when :float                       then 1.5
30
 
          when :decimal                     then "9.99"
31
 
          when :datetime, :timestamp, :time then Time.now.to_s(:db)
32
 
          when :date                        then Date.today.to_s(:db)
33
 
          when :string                      then "MyString"
34
 
          when :text                        then "MyText"
35
 
          when :boolean                     then false
36
 
          else
37
 
            ""
38
 
        end      
39
 
      end
40
 
 
41
 
      def reference?
42
 
        [ :references, :belongs_to ].include?(self.type)
43
 
      end
44
 
    end
45
 
  end
46
 
end