Class: Alchemy::Custom::Model::Cloner
- Inherits:
-
ActiveType::Object
- Object
- ActiveType::Object
- Alchemy::Custom::Model::Cloner
- Defined in:
- app/models/alchemy/custom/model/cloner.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#apply ⇒ Object
ritorna true se il clone è andato a buon fine false altrimenti.
Class Method Details
.cloner_of(name, scope = nil, options = {}) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/models/alchemy/custom/model/cloner.rb', line 38 def cloner_of(name,scope = nil, ={}) class_attribute :to_cloner_name name = name.to_sym if [:foreign_key] attribute [:foreign_key] else attribute :"#{name}_id" end belongs_to name, scope, self.to_cloner_name = name end |
Instance Method Details
#apply ⇒ Object
ritorna true se il clone è andato a buon fine false altrimenti
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/models/alchemy/custom/model/cloner.rb', line 17 def apply if valid? cloned = self.send(self.to_cloner_name).clone_to_other_lang(get_attributes_for_clone.with_indifferent_access) if cloned.valid? true else cloned.errors..each do | error| self.errors.add(:base, error) end false end else false end end |