Sha256: ecb4a8a8e8b14ee76b3b8bff43531cdaead49be6519b395688779a2e701eaa44
Contents?: true
Size: 1.78 KB
Versions: 1
Compression:
Stored size: 1.78 KB
Contents
module Mdd module Generators class ModelAttribute attr_accessor :name, :type, :reference, :reference_type STATIC_TYPES = [:boolean, :date, :datetime, :decimal, :float, :integer, :string, :text, :time, :timestamp, :file] def initialize( arg ) # sets the variables by the string split = arg.split(':') self.type = split[1] self.name = split[0] self.reference = split[2] self.reference_type = split[3] end def references? !STATIC_TYPES.include?(self.type.to_sym) end def name=(value) if references? and !value.end_with?('_id') @name = "#{value}_id" else @name = value end end def migration_field @migration_field ||= case self.type.to_sym when :string, :file then 'string' when :boolean then 'boolean' when :date then 'date' when :datetime then 'datetime' when :decimal, :float then 'decimal' when :text then 'text' when :time then 'time' when :timestamp then 'timestamp' else 'integer' end end def form_field @form_field ||= case self.type.to_sym when :integer then 'number_field' when :float, :decimal then 'text_field' when :file then 'file_field' when :time then 'time_select' when :datetime, :timestamp then 'datetime_select' when :date then 'date_select' when :text then 'text_area' when :boolean then 'check_box' else 'text_field' end "<%= f.#{@form_field} :#{self.name} %>" end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
mdd-1.1.0 | lib/mdd/generators/model_attribute.rb |