Sha256: 4103d023c4b960bcfdc3b3f4e53c5d0c5a14007261c428e4384a6cac7d162633

Contents?: true

Size: 942 Bytes

Versions: 2

Compression:

Stored size: 942 Bytes

Contents

module Kindergarten::ORM
  module ActiveRecord
    def self.included(base)
      base.extend(ClassMethods)
    end
    
    def update_attributes(hash)
      self.class.check(:update_attributes, hash)
    end
    
    module ClassMethods
      def create(*args)
        check(:create, *args)
        super
      end
      
      def new(*args)
        check(:new, *args)
        super
      end
      
      def check(method, *args)
        required = self.force_rinsed? ?
          Kindergarten::RinsedHash : 
          Kindergarten::ScrubbedHash

        if args[0].is_a?(Array)
          args.each do |input|
            raise Unscrubbed unless input.is_a?(required) 
          end

        elsif args[0].is_a?(Hash)
          raise Unscrubbed unless args[0].is_a?(required)
          
        elsif args.any?
          warn "WARNING: #{self.name}.#{method} called with unkown signature"
          
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
kindergarten-0.1.0 lib/kindergarten/orm/active_record.rb
kindergarten-0.0.5 lib/kindergarten/orm/active_record.rb