Methods
- D
- F
- H
- I
- N
- P
- R
Attributes
[RW] | name | |
[RW] | type | |
[R] | attr_options |
Class Public methods
# 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
# 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
# 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
# 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