Class: Stepford::Common
- Inherits:
-
Object
- Object
- Stepford::Common
- Defined in:
- lib/stepford/common.rb
Class Method Summary collapse
Class Method Details
.sequence_for(column) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/stepford/common.rb', line 3 def self.sequence_for(column) case column.type when :string, :text if column.name.to_s['email'] # n evaluated at runtime, so pound escaped "sequence(#{column.name.to_sym.inspect}) do |n|; \"person\#{n}@example.com\"; end" else # n evaluated at runtime, so pound escaped "sequence(#{column.name.to_sym.inspect}) do |n|; \"Test #{column.name.titleize} \#{n}\"; end" end when :integer, :decimal, :float, :date, :datetime, :timestamp, :binary, :ts_vector, :boolean "sequence(#{column.name.to_sym.inspect})" when :xml "sequence(#{column.name.to_sym.inspect}) do |n|; \"<test>Test #{column.name.titleize} \#{n}</test>\"; end" else puts "Stepford does not know how to generate a sequence value for column type #{column.type.to_sym}" column.default.nil? ? 'nil' : column.default.to_s end end |
.value_for(column) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/stepford/common.rb', line 22 def self.value_for(column) case column.type when :string, :text if column.default.nil? result = "Test #{column.name.titleize}" column.limit && column.limit < result.size ? (column.limit >= 0 ? "'#{'a' * column.limit}'" : 'nil') : "'#{result}'" else "'#{column.default}'" end when :integer column.default.nil? ? (column.limit ? column.limit.to_s : '123') : column.default.to_s when :decimal, :float column.default.nil? ? (column.limit ? column.limit.to_s : '1.23') : column.default.to_s when :date, :datetime, :timestamp '{ 2.weeks.ago }' when :binary column.default.nil? ? (column.limit ? column.limit.to_s : '0b010101') : column.default.to_s when :boolean column.default.nil? ? 'true' : column.default.to_s when :xml column.default.nil? ? '<test>Test #{column.name.titleize}</test>' : column.default.to_s when :ts_vector column.default.nil? ? 'nil' : column.default.to_s else puts "Stepford does not know how to generate a value for column type #{column.type.to_sym}" column.default.nil? ? 'nil' : column.default.to_s end end |