Sha256: b023151a3a70a7c0ac5fad727beefaffca74703042aa6c2e86365102564ae6a5
Contents?: true
Size: 1.57 KB
Versions: 2
Compression:
Stored size: 1.57 KB
Contents
module Mack module Genosaurus module DataMapper # Used to represent a 'column' from the param cols or columns for generators. class ModelColumn # The name of the column. attr_accessor :column_name # The type of the column. Ie. string, integer, datetime, etc... attr_accessor :column_type # The name of the model associated with the column. Ie. user, post, etc... attr_accessor :model_name # Takes in the model_name (user, post, etc...) and the column (username:string, body:text, etc...) def initialize(model_name, column_unsplit) self.model_name = model_name.singular.underscore cols = column_unsplit.split(":") self.column_name = cols.first#.underscore self.column_type = cols.last#.underscore end # Generates the appropriate HTML form field for the type of column represented. # # Examples: # Mack::Generator::ColumnObject.new("user", "username:string").form_field # => "<%= model_text_field(@user, :username) %>" # Mack::Generator::ColumnObject.new("Post", "body:text").form_field # => "<%= model_textarea(@user, :username) %>" def form_field case self.column_type when "text" %{<%= model_textarea(@#{self.model_name}, :#{self.column_name}) %>} else %{<%= model_text_field(@#{self.model_name}, :#{self.column_name}) %>} end end end # ModelColumn end # DataMapper end # Generator end # Mack
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
mack-data_mapper-0.6.0 | lib/model_column.rb |
mack-data_mapper-0.6.0.1 | lib/model_column.rb |