Sha256: d076108883a3534fe799b55e8c86384021201dcbed2a01daa235d10d76a30935

Contents?: true

Size: 1.7 KB

Versions: 21

Compression:

Stored size: 1.7 KB

Contents

module Knitkit
  module Extensions
    module ActiveRecord
      module ActsAsDocument
        def self.included(base)
          base.extend(ClassMethods)
        end

        module ClassMethods

          def acts_as_document
            extend ActsAsDocument::SingletonMethods
            include ActsAsDocument::InstanceMethods

            after_initialize :initialize_document
  					after_create :save_document
  					after_update :save_document
  					after_destroy :destroy_document

            has_one :document, :as => :document_record

            #from Document / FileAssets
            [:add_file, :files].each { |m| delegate m, :to => :document }

            #from relational_dynamic_attributes
            [
            :add_dynamic_attribute,
            :update_or_create_dynamic_attribute,
            :update_first_dynamic_attribute_value_of_type,
            :get_dynamic_attributes,
            :get_dynamic_value_of_type,
            :get_dynamic_attribute_of_type,
            :has_dynamic_attribute_of_type?,
            :destroy_dynamic_attribute_of_type
            ].each { |m| delegate m, :to => :document }
          end

        end

        module SingletonMethods
        end

        module InstanceMethods
          def save_document
            self.document.save
				  end

				  def destroy_document
            self.document.destroy
				  end

				  def initialize_document
            if self.new_record? and self.document.nil?
              self.document = Document.new
              self.document.document_record = self
            end
				  end
        end

      end#ActsAsDocument
    end#ActiveRecord
  end#Extensions
end#Knitkit

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
knitkit-2.1.15 lib/knitkit/extensions/active_record/acts_as_document.rb
knitkit-2.1.14 lib/knitkit/extensions/active_record/acts_as_document.rb
knitkit-2.1.13 lib/knitkit/extensions/active_record/acts_as_document.rb
knitkit-2.1.12 lib/knitkit/extensions/active_record/acts_as_document.rb
knitkit-2.1.11 lib/knitkit/extensions/active_record/acts_as_document.rb
knitkit-2.1.10 lib/knitkit/extensions/active_record/acts_as_document.rb
knitkit-2.1.9 lib/knitkit/extensions/active_record/acts_as_document.rb
knitkit-2.1.8 lib/knitkit/extensions/active_record/acts_as_document.rb
knitkit-2.1.7 lib/knitkit/extensions/active_record/acts_as_document.rb
knitkit-2.1.6 lib/knitkit/extensions/active_record/acts_as_document.rb
knitkit-2.1.5 lib/knitkit/extensions/active_record/acts_as_document.rb
knitkit-2.1.4 lib/knitkit/extensions/active_record/acts_as_document.rb
knitkit-2.1.3 lib/knitkit/extensions/active_record/acts_as_document.rb
knitkit-2.1.2 lib/knitkit/extensions/active_record/acts_as_document.rb
knitkit-2.1.1 lib/knitkit/extensions/active_record/acts_as_document.rb
knitkit-2.1.0 lib/knitkit/extensions/active_record/acts_as_document.rb
knitkit-2.0.11 lib/knitkit/extensions/active_record/acts_as_document.rb
knitkit-2.0.10 lib/knitkit/extensions/active_record/acts_as_document.rb
knitkit-2.0.9 lib/knitkit/extensions/active_record/acts_as_document.rb
knitkit-2.0.7 lib/knitkit/extensions/active_record/acts_as_document.rb