Module: ConcernsOnRails::Models::Duplicable::ClassMethods
- Includes:
- Support::ColumnGuard
- Defined in:
- lib/concerns_on_rails/models/duplicable.rb
Instance Method Summary collapse
-
#duplicable_by(associations: [], reset: [], suffix: {}) ⇒ Object
Configure the copy rules.
Methods included from Support::ColumnGuard
#ensure_columns!, #ensure_columns_on!, #schema_reachable?
Instance Method Details
#duplicable_by(associations: [], reset: [], suffix: {}) ⇒ Object
Configure the copy rules. Optional — duplicate works with bare
include (attribute copy + the automatic identity resets).
69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/concerns_on_rails/models/duplicable.rb', line 69 def duplicable_by(associations: [], reset: [], suffix: {}) associations = Array(associations).map(&:to_sym) reset = Array(reset).map(&:to_sym) suffix = suffix.to_h { |field, text| [field.to_sym, text.to_s] } duplicable_validate_associations!(associations) ensure_columns!(LABEL, reset) unless reset.empty? ensure_columns!(LABEL, suffix.keys) unless suffix.empty? self.duplicable_config = { associations: associations, reset: reset, suffix: suffix }.freeze end |