Module: Renderable::TableDefinition
- Defined in:
- lib/renderable/schema.rb
Instance Method Summary collapse
-
#renderable(field_name, field_type = :string, options = {}) ⇒ Object
Adds a renderable field to the current table.
Instance Method Details
#renderable(field_name, field_type = :string, options = {}) ⇒ Object
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
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/renderable/schema.rb', line 80 def renderable( field_name, field_type = :string, = {} ) raise ArgumentError "Please specify name of field in renderable call in your migration" if field_name.blank? # get suffix suffix = .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 = field_type # default field_type again field_type = :string end # add columns column field_name, field_type, column "#{field_name}#{suffix}", field_type, end |