Sha256: 3623c3ba23ca8e11d1218273bed67a918cbb133217533be621e550156c487991

Contents?: true

Size: 1.88 KB

Versions: 6

Compression:

Stored size: 1.88 KB

Contents

module Rails3Generators
  module Helpers
    module Model 

      attr_accessor :model_attributes, :model_indexes

      def parse_model_attributes(with_indexes = true)
        @model_attributes = []        
        @model_indexes = {}
        # 
        # attributes.each do |arg|
        #   if with_indexes
        #     # extract index markers
        #     if arg.include?('#')  
        #       arg.gsub! /#.*$/, ''            
        #       model_indexes[arg_name(arg).to_sym] = true
        #     end
        #   end
        # 
        #   if arg.include?(':')
        #     model_attributes << Rails::Generators::GeneratedAttribute.new(*arg.split(':'))
        #   else
        #     model_attributes << Rails::Generators::GeneratedAttribute.new(arg, "string")            
        #   end
        # 
        #   model_attributes.uniq!
        # 
        #   if model_attributes.empty?
        #     if model_exists?
        #       model_columns_for_attributes.each do |column|
        #         model_attributes << Rails::Generators::GeneratedAttribute.new(column.name.to_s, column.type.to_s)
        #       end
        #     else
        #       model_attributes << Rails::Generators::GeneratedAttribute.new('name', 'string')
        #     end
        #   end
        # end 
      end      

      def arg_name(arg)
        arg.split(':').first        
      end

      def arg_type(arg)
        arg.split(':')[1] || 'string'
      end
      
      def model_name
        name
      end      
      
      def model_exists?
        File.exist? destination_path("app/models/#{singular_name}.rb")
      end

      def singular_name
        model_name.underscore
      end

      def plural_name
        model_name.underscore.pluralize
      end

      def class_name
        model_name.camelize
      end

      def plural_class_name
        plural_name.camelize
      end
    end
  end
end
            
    

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rails3-generators-0.15.0 lib/generators/helpers/model_helper.rb
rails3-generators-0.14.0 lib/generators/helpers/model_helper.rb
rails3-generators-0.13.0 lib/generators/helpers/model_helper.rb
rails3-generators-0.12.1 lib/generators/helpers/model_helper.rb
rails3-generators-0.12.0 lib/generators/helpers/model_helper.rb
rails3-generators-0.11.0 lib/generators/helpers/model_helper.rb