Module: PassiveRecord::Associations

Defined in:
lib/passive_record/associations.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/passive_record/associations.rb', line 6

def self.included(base)
  base.extend(ClassMethods)

  ActiveRecord::Callbacks::CALLBACKS.each do |method|
    base.class_eval <<-"end_eval"
      def self.#{method}(*callbacks, &block)
        callbacks << block if block_given?
        write_inheritable_array(#{method.to_sym.inspect}, callbacks)
      end
    end_eval
  end
end

Instance Method Details

#attribute_present?(attribute) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
# File 'lib/passive_record/associations.rb', line 23

def attribute_present?(attribute)
  value = self.respond_to?(attribute) ? self.send(attribute) : nil
  !value.blank? or value == 0
end

#new_record?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/passive_record/associations.rb', line 32

def new_record?
  false
end

#quoted_idObject

:nodoc:



19
20
21
# File 'lib/passive_record/associations.rb', line 19

def quoted_id #:nodoc:
  ActiveRecord::Base.quote_value(self.key)
end

#read_attribute(attribute) ⇒ Object



28
29
30
# File 'lib/passive_record/associations.rb', line 28

def read_attribute(attribute)
  self.send(attribute)
end