Class: Rails::Generators::GeneratedAttribute

Inherits:
Object
  • Object
show all
Defined in:
lib/generators/rspec/default_values.rb,
lib/generators/rspec/scaffold/scaffold_generator.rb

Instance Method Summary collapse

Instance Method Details

#default_valueObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/generators/rspec/default_values.rb', line 4

def default_value
  @default_value ||= case type
    when :int, :integer               then "1"
    when :float                       then "1.5"
    when :decimal                     then "9.99"
    when :datetime, :timestamp, :time then "Time.now"
    when :date                        then "Date.today"
    when :string, :text               then "\"value for #{@name}\""
    when :boolean                     then "false"
    when :belongs_to, :references     then "1"
    else
      ""
  end
end

#input_typeObject



200
201
202
# File 'lib/generators/rspec/scaffold/scaffold_generator.rb', line 200

def input_type
  @input_type ||= map_to_input_type      
end

#name_or_referenceObject



23
24
25
26
27
28
29
# File 'lib/generators/rspec/default_values.rb', line 23

def name_or_reference
  if ::Rails::VERSION::STRING >= '2.2'
    reference? ? :"#{name}_id" : name
  else
    name
  end
end

#to_sObject



19
20
21
# File 'lib/generators/rspec/default_values.rb', line 19

def to_s
  "#{name}:#{type}"
end