Module: ActiveRecord::Duplicate::ClassMethods
- Defined in:
- lib/activerecord-duplicate/duplicate.rb
Instance Method Summary collapse
- #after_duplication(*args, &block) ⇒ Object
- #attr_duplicatable(*attributes) ⇒ Object
- #attr_duplicatable?(attribute) ⇒ Boolean
-
#before_duplication(*args, &block) ⇒ Object
Duplicated from activemodel/lib/active_model/validations/callbacks.rb.
Instance Method Details
#after_duplication(*args, &block) ⇒ Object
92 93 94 95 96 97 98 99 100 101 |
# File 'lib/activerecord-duplicate/duplicate.rb', line 92 def after_duplication(*args, &block) = args. [:prepend] = true [:if] = Array.wrap([:if]) [:if] << "!halted" [:if].unshift("self.duplication_context == :#{[:on]}") if [:on] set_callback(:duplication, :after, *(args << ), &block) end |
#attr_duplicatable(*attributes) ⇒ Object
69 70 71 72 73 |
# File 'lib/activerecord-duplicate/duplicate.rb', line 69 def attr_duplicatable(*attributes) self._duplicatable_attributes ||= [] self._duplicatable_attributes = _duplicatable_attributes | attributes.map(&:to_sym) if attributes.present? self._duplicatable_attributes end |
#attr_duplicatable?(attribute) ⇒ Boolean
75 76 77 78 |
# File 'lib/activerecord-duplicate/duplicate.rb', line 75 def attr_duplicatable?(attribute) attribute = attribute.to_sym attr_duplicatable.present? ? attr_duplicatable.include?(attribute) : primary_key.to_sym != attribute end |
#before_duplication(*args, &block) ⇒ Object
Duplicated from activemodel/lib/active_model/validations/callbacks.rb
81 82 83 84 85 86 87 88 89 90 |
# File 'lib/activerecord-duplicate/duplicate.rb', line 81 def before_duplication(*args, &block) = args.last if .is_a?(Hash) && [:on] [:if] = Array.wrap([:if]) [:if].unshift("self.duplication_context == :#{[:on]}") end set_callback(:duplication, :before, *args, &block) end |