Sha256: 4b63c39c01d65b796ef5260908b85d9fd6ced34a5e80d8ba5377d9f5494f0c0c

Contents?: true

Size: 1.26 KB

Versions: 1

Compression:

Stored size: 1.26 KB

Contents

##
# MongoMapper adapter to ExtJS::Model mixin
#
module ExtJS
  module Model
    ##
    # ClassMethods
    #
    module ClassMethods

      def extjs_primary_key
        :_id
      end

      def extjs_column_names
        self.column_names
      end

      def extjs_columns_hash
        self.keys
      end

      def extjs_associations
        if @extjs_associations.nil?
          @extjs_associations = {}
          self.associations.keys.each do |key|
            @extjs_associations[key.to_sym] = {
              :name => key,
              :type => self.associations[key].type,
              :class => self.associations[key].class_name.constantize,
              :foreign_key => self.associations[key].foreign_key
            }
          end
        end
        @extjs_associations
      end

      def extjs_type(col)
        type = col.type.to_s
        case type
          when "DateTime", "Date", "Time"
            type = :date
          when "String"
            type = :string
          when "Float"
            type = :float
          when "Integer", "BigDecimal"
            type = :int
          else
            type = "auto"
        end
      end

      def extjs_allow_blank(col)
        (col.name == '_id') || (col.options[:required] != true)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
extjs-mvc-0.2.8 lib/model/mongo_mapper.rb