Kiss A simpler, smarter web application framework for Ruby

Kiss::Model Subclass of Sequel::Model

Description

This class adds functionality to Sequel::Model and automatically loads model class definitions from model_dir. It also uses Kiss#file_cache to cache database model classes, unless no model_dir is specified.

Public Class Methods

associate(type, name, opts = {}, &block) source

TODO: Fix has_many and many_to_many associations

    # File lib/kiss/model.rb, line 39
      def associate(type, name, opts = {}, &block)
        opts = opts.clone
        
        unless opts[:class] || opts[:class_name]
          opts[:class_name] = name.to_s.singularize
        end
        
        super(type, name, opts, &block)
        
        association_reflections[name]
      end
    
controller() source

Not documented

    # File lib/kiss/model.rb, line 17
      def controller
        db.kiss_controller
      end
    
default_foreign_key() source

Name symbol for default foreign key

    # File lib/kiss/model.rb, line 30
      def default_foreign_key
        :"#{name.singularize.demodulize.underscore}_id"
      end
    
find_or_new(cond) source

Not documented

    # File lib/kiss/model.rb, line 34
      def find_or_new(cond)
        find(cond) || new(cond)
      end
    
name() source

This method is called by Sequel::Model’s association def methods. Must return singularized table name for correct association key names.

    # File lib/kiss/model.rb, line 13
      def name
        @table.to_s.singularize
      end
    
set_dataset(source) source

Not documented

    # File lib/kiss/model.rb, line 7
      def set_dataset(source)
        super(source)
      end
    
table() source

Not documented

    # File lib/kiss/model.rb, line 21
      def table
        @table.to_sym
      end
    
table=(table) source

Not documented

    # File lib/kiss/model.rb, line 25
      def table=(table)
        @table = table
      end
    

Public Instance Methods

controller() source

Not documented

    # File lib/kiss/model.rb, line 58
    def controller
      self.class.controller
    end
    
method_missing(meth) source

Not documented

    # File lib/kiss/model.rb, line 54
    def method_missing(meth)
      raise NoMethodError, "undefined method `#{meth}' for database model `#{self.class.name}'"
    end
    

Disabled; run with $DEBUG to generate this.