Sha256: e5e5266e1c9e909501227757f858fba47ec4f1565546f6575518294068836792

Contents?: true

Size: 1.05 KB

Versions: 3

Compression:

Stored size: 1.05 KB

Contents

module Alchemy
  module Custom
    module Model
      class Cloner < ::ActiveType::Object

        attribute :language_id, :integer
        attribute :site_id, :integer

        validates :language_id, :site_id, presence: true
        validate :check_lang_in_site, unless: -> {site_id.blank?}


        ###
        # ritorna true se il clone รจ andato a buon fine false altrimenti
        def apply
          if valid?
            cloned = self.category.clone_to_other_lang self.attributes.with_indifferent_access
            if cloned.valid?
              true
            else
              cloned.errors.full_messages.each do | error|
                self.errors.add(:base, error)
              end
              false
            end
          else
            false
          end
        end



        protected

        def check_lang_in_site
          site = Alchemy::Site.find self.site_id
          if !site.languages.pluck(:id).include? self.language_id
            errors.add(:language_id, :isnt_in_site)
          end
        end

      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
alchemy-custom-model-2.0.1 app/models/alchemy/custom/model/cloner.rb
alchemy-custom-model-2.0.0 app/models/alchemy/custom/model/cloner.rb
alchemy-custom-model-0.1.9 app/models/alchemy/custom/model/cloner.rb