Class: Effective::Merge
- Inherits:
-
Object
- Object
- Effective::Merge
- Includes:
- ActiveModel::Model
- Defined in:
- app/models/effective/merge.rb
Instance Attribute Summary collapse
-
#source ⇒ Object
Returns the value of attribute source.
-
#source_id ⇒ Object
Returns the value of attribute source_id.
-
#target ⇒ Object
Returns the value of attribute target.
-
#target_id ⇒ Object
Returns the value of attribute target_id.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #collection ⇒ Object
- #form_collection ⇒ Object
- #klass ⇒ Object
- #save(validate: true) ⇒ Object
- #save!(validate: true) ⇒ Object
- #to_s ⇒ Object
-
#validate_klass! ⇒ Object
This is called on Admin::Merges#new.
Instance Attribute Details
#source ⇒ Object
Returns the value of attribute source.
5 6 7 |
# File 'app/models/effective/merge.rb', line 5 def source @source end |
#source_id ⇒ Object
Returns the value of attribute source_id.
5 6 7 |
# File 'app/models/effective/merge.rb', line 5 def source_id @source_id end |
#target ⇒ Object
Returns the value of attribute target.
5 6 7 |
# File 'app/models/effective/merge.rb', line 5 def target @target end |
#target_id ⇒ Object
Returns the value of attribute target_id.
5 6 7 |
# File 'app/models/effective/merge.rb', line 5 def target_id @target_id end |
#type ⇒ Object
Returns the value of attribute type.
5 6 7 |
# File 'app/models/effective/merge.rb', line 5 def type @type end |
Instance Method Details
#collection ⇒ Object
36 37 38 |
# File 'app/models/effective/merge.rb', line 36 def collection @collection ||= (klass.respond_to?(:effective_mergery_collection) ? klass.effective_mergery_collection : klass.all) end |
#form_collection ⇒ Object
40 41 42 |
# File 'app/models/effective/merge.rb', line 40 def form_collection @form_collection ||= (klass.respond_to?(:effective_mergery_form_collection) ? klass.effective_mergery_form_collection : collection) end |
#klass ⇒ Object
44 45 46 |
# File 'app/models/effective/merge.rb', line 44 def klass @klass ||= type.safe_constantize end |
#save(validate: true) ⇒ Object
26 27 28 29 |
# File 'app/models/effective/merge.rb', line 26 def save(validate: true) return false unless valid? (merge!(validate: validate) rescue false) end |
#save!(validate: true) ⇒ Object
31 32 33 34 |
# File 'app/models/effective/merge.rb', line 31 def save!(validate: true) raise 'is invalid' unless valid? merge!(validate: validate) end |
#to_s ⇒ Object
21 22 23 24 |
# File 'app/models/effective/merge.rb', line 21 def to_s return 'New Merge' unless type type.downcase end |
#validate_klass! ⇒ Object
This is called on Admin::Merges#new
49 50 51 52 53 54 55 |
# File 'app/models/effective/merge.rb', line 49 def validate_klass! raise "type can't be blank" unless type.present? raise 'type must be a mergable type' unless EffectiveMergery.mergables.include?(type) raise "invalid ActiveRecord klass" unless klass raise "invalid ActiveRecord collection" unless collection.kind_of?(ActiveRecord::Relation) true end |