Module: RecordWithOperator::Extension::ClassMethods

Defined in:
lib/record_with_operator/extension.rb

Instance Method Summary collapse

Instance Method Details

#create_operator_associationsObject



37
38
39
40
41
42
43
44
45
46
# File 'lib/record_with_operator/extension.rb', line 37

def create_operator_associations
  return if operator_associations_created?
  @operator_associations_created = true

  if self.table_exists?
    belongs_to :creator, {:foreign_key => "created_by", :class_name => RecordWithOperator.config[:user_class_name]}.merge(RecordWithOperator.config[:operator_association_options]) if column_names.include?('created_by')
    belongs_to :updater, {:foreign_key => "updated_by", :class_name => RecordWithOperator.config[:user_class_name]}.merge(RecordWithOperator.config[:operator_association_options]) if column_names.include?('updated_by')
    belongs_to :deleter, {:foreign_key => "deleted_by", :class_name => RecordWithOperator.config[:user_class_name]}.merge(RecordWithOperator.config[:operator_association_options]) if column_names.include?('deleted_by')
  end
end

#has_many_with_operator(*args, &extension) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/record_with_operator/extension.rb', line 48

def has_many_with_operator(*args, &extension)
  options = args.extract_options!
  # add AssociationWithOprator to :extend
  if options[:extend]
    options[:extend] = [options[:extend]] unless options[:extend].kind_of? Array
    options[:extend] << RecordWithOperator::Associations::Extension
  else
    options[:extend] = RecordWithOperator::Associations::Extension
  end
  # add :set_operator to :before_add
  if options[:before_add]
    options[:before_add] = [options[:before_add]] unless options[:before_add].kind_of? Array
    options[:before_add] << :set_operator
  else
    options[:before_add] = :set_operator
  end
  args << options
  has_many_without_operator(*args, &extension)
end

#operator_associations_created?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/record_with_operator/extension.rb', line 33

def operator_associations_created?
  @operator_associations_created
end

#reflections_with_operatorObject



28
29
30
31
# File 'lib/record_with_operator/extension.rb', line 28

def reflections_with_operator
  create_operator_associations
  reflections_without_operator
end