Sha256: 91f709cd4540672ecc75e025e5b11fc027295ab65d5437321871fade6ab01937

Contents?: true

Size: 798 Bytes

Versions: 16

Compression:

Stored size: 798 Bytes

Contents

require 'active_record'

class ActiveRecord::Base
  
  def self.validates_path(*args)
    configuration = args.extract_options!
    validates_each(args, configuration) do |record, attr_name, value|
      page = Page.find_by_path(value)
      record.errors.add(attr_name, :page_not_found, :default => configuration[:message]) if page.nil? || page.is_a?(FileNotFoundPage)
    end
  end
  
  def self.object_id_attr(symbol, klass)
    module_eval %{
      def #{symbol}
        if @#{symbol}.nil? or (@old_#{symbol}_id != #{symbol}_id)
          @old_#{symbol}_id = #{symbol}_id
          klass = #{klass}.descendants.find { |d| d.#{symbol}_name == #{symbol}_id }
          klass ||= #{klass}
          @#{symbol} = klass.new
        else
          @#{symbol}
        end
      end
    }
  end
  
end

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
radiant-1.1.4 lib/plugins/active_record_extensions/lib/active_record_extensions.rb
radiant-1.1.3 lib/plugins/active_record_extensions/lib/active_record_extensions.rb
radiant-1.1.2 lib/plugins/active_record_extensions/lib/active_record_extensions.rb
radiant-1.1.1 lib/plugins/active_record_extensions/lib/active_record_extensions.rb
radiant-1.1.0 lib/plugins/active_record_extensions/lib/active_record_extensions.rb
radiant-1.1.0.rc1 lib/plugins/active_record_extensions/lib/active_record_extensions.rb
radiant-1.1.0.beta lib/plugins/active_record_extensions/lib/active_record_extensions.rb
radiant-1.0.1 lib/plugins/active_record_extensions/lib/active_record_extensions.rb
radiant-1.1.0.alpha lib/plugins/active_record_extensions/lib/active_record_extensions.rb
radiant-1.0.0 lib/plugins/active_record_extensions/lib/active_record_extensions.rb
radiant-1.0.0.rc5 lib/plugins/active_record_extensions/lib/active_record_extensions.rb
radiant-1.0.0.rc4 lib/plugins/active_record_extensions/lib/active_record_extensions.rb
radiant-1.0.0.rc3 lib/plugins/active_record_extensions/lib/active_record_extensions.rb
kajam-1.0.3.rc2 lib/plugins/active_record_extensions/lib/active_record_extensions.rb
radiant-1.0.0.rc2 lib/plugins/active_record_extensions/lib/active_record_extensions.rb
radiant-1.0.0.rc1 lib/plugins/active_record_extensions/lib/active_record_extensions.rb