Sha256: 66093834d8cb13e8adb0ead032d24464f98c2df68b036b3cc1902d5c03757881

Contents?: true

Size: 1.49 KB

Versions: 1

Compression:

Stored size: 1.49 KB

Contents

require 'sequel'

module Sequel
  module Plugins
    # This is used by Clevic to talk to models. It's here because
    # I'd rather keep some kind of layer in case it's necessary
    # to become more pluggable in relation to ORM frameworks.
    module Clevic
      def self.configure(model, options = {})
        model.instance_eval do
          # store model-related stuff here
        end
      end
      
      module ClassMethods
        # Copy the necessary class instance variables to the subclass.
        def inherited(subclass)
          super
        end
        
        # This doesn't really belong here, but I don't want to make 
        # a whole new plugin.
        def table_exists?
          db.table_exists?( implicit_table_name )
        end
        
        # Hmm, maybe these need to go in a different plugin
        def column_names
          columns
        end
        
        # Getting heavy enough, yet?
        def reflections
          association_reflections 
        end
        
      end
      
      module InstanceMethods
        # This should also go in another plugin
        def changed?
          modified?
        end
        
        def readonly?
          false
        end
      
        def new_record?
          new?
        end
      end
    end
  end
end

Sequel::Model.plugin :clevic

# This doesn't seem to work inside the plugin
module Sequel
  class Model
    class Errors
      def invalid?( field_name )
        self.has_key?( field_name )
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
clevic-0.13.0.b5 lib/clevic/sequel_clevic.rb