module Renderable::TableDefinition
Public Instance Methods
renderable( field_name, field_type = :string, options = {} )
click to toggle source
Adds a renderable field to the current table. This is used inside a create_table block.
Parameters¶ ↑
- field_name
-
the name of the field to add
- field_type
-
the type of the field to add
- options
-
any additional options to be passed to add_column
# File lib/renderable/schema.rb, line 80 def renderable( field_name, field_type = :string, options = {} ) raise ArgumentError "Please specify name of field in renderable call in your migration" if field_name.blank? # get suffix suffix = options.delete(:suffix) { |k| '_rendered' } # bugfix: if we don’t specify a field type but do specify options, it snarfs things up, so resolve that here # @TODO: is there a better way of doing this in Ruby? if field_type.is_a? Hash # copy field_type hash to options options = field_type # default field_type again field_type = :string end # add columns column field_name, field_type, options column "#{field_name}#{suffix}", field_type, options end