Methods
D
F
H
I
N
P
R
Attributes
[RW] name
[RW] type
[R] attr_options
Class Public methods
new(name, type=nil, index_type=false, attr_options={})
    # File railties/lib/rails/generators/generated_attribute.rb, line 40
40:       def initialize(name, type=nil, index_type=false, attr_options={})
41:         @name           = name
42:         @type           = (type.presence || :string).to_sym
43:         @has_index      = %w(index uniq).include?(index_type)
44:         @has_uniq_index = %w(uniq).include?(index_type)
45:         @attr_options   = attr_options
46:       end
parse(column_definition)
    # File railties/lib/rails/generators/generated_attribute.rb, line 12
12:         def parse(column_definition)
13:           name, type, has_index = column_definition.split(':')
14: 
15:           # if user provided "name:index" instead of "name:string:index"
16:           # type should be set blank so GeneratedAttribute's constructor
17:           # could set it to :string
18:           has_index, type = type, nil if %w(index uniq).include?(type)
19: 
20:           type, attr_options = *parse_type_and_options(type)
21:           new(name, type, has_index, attr_options)
22:         end
Instance Public methods
default()
    # File railties/lib/rails/generators/generated_attribute.rb, line 62
62:       def default
63:         @default ||= case type
64:           when :integer                     then 1
65:           when :float                       then 1.5
66:           when :decimal                     then "9.99"
67:           when :datetime, :timestamp, :time then Time.now.to_s(:db)
68:           when :date                        then Date.today.to_s(:db)
69:           when :string                      then name == "type" ? "" : "MyString"
70:           when :text                        then "MyText"
71:           when :boolean                     then false
72:           when :references, :belongs_to     then nil
73:           else
74:             ""
75:         end
76:       end
field_type()
    # File railties/lib/rails/generators/generated_attribute.rb, line 48
48:       def field_type
49:         @field_type ||= case type
50:           when :integer              then :number_field
51:           when :float, :decimal      then :text_field
52:           when :time                 then :time_select
53:           when :datetime, :timestamp then :datetime_select
54:           when :date                 then :date_select
55:           when :text                 then :text_area
56:           when :boolean              then :check_box
57:           else
58:             :text_field
59:         end
60:       end
has_index?()
    # File railties/lib/rails/generators/generated_attribute.rb, line 90
90:       def has_index?
91:         @has_index
92:       end
has_uniq_index?()
    # File railties/lib/rails/generators/generated_attribute.rb, line 94
94:       def has_uniq_index?
95:         @has_uniq_index
96:       end
human_name()
    # File railties/lib/rails/generators/generated_attribute.rb, line 78
78:       def human_name
79:         name.to_s.humanize
80:       end
index_name()
    # File railties/lib/rails/generators/generated_attribute.rb, line 82
82:       def index_name
83:         reference? ? "#{name}_id" : name
84:       end
inject_index_options()
     # File railties/lib/rails/generators/generated_attribute.rb, line 102
102:       def inject_index_options
103:         has_uniq_index? ? ", :unique => true" : ''
104:       end
inject_options()
     # File railties/lib/rails/generators/generated_attribute.rb, line 98
 98:       def inject_options
 99:         "".tap { |s| @attr_options.each { |k,v| s << ", :#{k} => #{v.inspect}" } }
100:       end
reference?()
    # File railties/lib/rails/generators/generated_attribute.rb, line 86
86:       def reference?
87:         self.type.in?([:references, :belongs_to])
88:       end