Module: RecordWithOperator::Extension::ClassMethods
- Defined in:
- lib/record_with_operator/extension.rb
Instance Method Summary collapse
- #create_operator_associations ⇒ Object
- #has_many_with_operator(*args, &extension) ⇒ Object
- #operator_associations_created? ⇒ Boolean
- #reflections_with_operator ⇒ Object
Instance Method Details
#create_operator_associations ⇒ Object
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) = args. # add AssociationWithOprator to :extend if [:extend] [:extend] = [[:extend]] unless [:extend].kind_of? Array [:extend] << RecordWithOperator::Associations::Extension else [:extend] = RecordWithOperator::Associations::Extension end # add :set_operator to :before_add if [:before_add] [:before_add] = [[:before_add]] unless [:before_add].kind_of? Array [:before_add] << :set_operator else [:before_add] = :set_operator end args << has_many_without_operator(*args, &extension) end |
#operator_associations_created? ⇒ Boolean
33 34 35 |
# File 'lib/record_with_operator/extension.rb', line 33 def operator_associations_created? @operator_associations_created end |
#reflections_with_operator ⇒ Object
28 29 30 31 |
# File 'lib/record_with_operator/extension.rb', line 28 def reflections_with_operator create_operator_associations reflections_without_operator end |