Sha256: f996cce6bf6995b67be91389fc30e78b1f9967d6e33c1696e02268662874aae6

Contents?: true

Size: 1.48 KB

Versions: 25

Compression:

Stored size: 1.48 KB

Contents

require 'optparse'

module Rails
  module Generator
    class GeneratedAttribute
      attr_accessor :name, :type, :column

      def initialize(name, type)
        @name, @type = name, type.to_sym
        @column = ActiveRecord::ConnectionAdapters::Column.new(name, nil, @type)
      end

      def field_type
        @field_type ||= case type
          when :integer, :float, :decimal then :text_field
          when :time                      then :time_select
          when :datetime, :timestamp      then :datetime_select
          when :date                      then :date_select
          when :string                    then :text_field
          when :text                      then :text_area
          when :boolean                   then :check_box
          else
            :text_field
        end      
      end

      def default
        @default ||= case type
          when :integer                     then 1
          when :float                       then 1.5
          when :decimal                     then "9.99"
          when :datetime, :timestamp, :time then Time.now.to_s(:db)
          when :date                        then Date.today.to_s(:db)
          when :string                      then "MyString"
          when :text                        then "MyText"
          when :boolean                     then false
          else
            ""
        end      
      end

      def reference?
        [ :references, :belongs_to ].include?(self.type)
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 5 rubygems

Version Path
rails-2.3.18 lib/rails_generator/generated_attribute.rb
rails-2.3.17 lib/rails_generator/generated_attribute.rb
rails-2.3.16 lib/rails_generator/generated_attribute.rb
rails-2.3.15 lib/rails_generator/generated_attribute.rb
radiant-1.0.0 ruby-debug/ruby/1.8/gems/rails-2.3.14/lib/rails_generator/generated_attribute.rb
vanity-1.7.1 vendor/ruby/1.9.1/gems/rails-2.3.12/lib/rails_generator/generated_attribute.rb
rails-2.3.14 lib/rails_generator/generated_attribute.rb
kajam-1.0.3.rc2 vendor/rails/railties/lib/rails_generator/generated_attribute.rb
rails-2.3.12 lib/rails_generator/generated_attribute.rb
radiant-1.0.0.rc2 vendor/rails/railties/lib/rails_generator/generated_attribute.rb
radiant-1.0.0.rc1 vendor/rails/railties/lib/rails_generator/generated_attribute.rb
rails-2.3.11 lib/rails_generator/generated_attribute.rb
radiantcms-couchrest_model-0.1.4 vendor/rails/railties/lib/rails_generator/generated_attribute.rb
radiantcms-couchrest_model-0.1.3 vendor/rails/railties/lib/rails_generator/generated_attribute.rb
radiantcms-couchrest_model-0.1.2 vendor/rails/railties/lib/rails_generator/generated_attribute.rb
radiantcms-couchrest_model-0.1.1 vendor/rails/railties/lib/rails_generator/generated_attribute.rb
radiantcms-couchrest_model-0.1 vendor/rails/railties/lib/rails_generator/generated_attribute.rb
rails-2.3.10 lib/rails_generator/generated_attribute.rb
rails-2.3.9 lib/rails_generator/generated_attribute.rb
rails-2.3.9.pre lib/rails_generator/generated_attribute.rb