Sha256: 6aaec5dc21720601d451b6874adee4847f885beb7a138a688ba7f5491272890d

Contents?: true

Size: 1.27 KB

Versions: 31

Compression:

Stored size: 1.27 KB

Contents

# -*- encoding : utf-8 -*-
module Reactor
  module Plans
    class CommonAttributeGroup
      include Prepared

      ALLOWED_PARAMS = [:title, :index]

      def initialize
        @params = {}
      end

      def set(key,value)
        key = key.to_sym
        if key == :attributes
          @attributes = value
        else
          @params[key.to_sym] = value
        end
      end

      def add_attributes(attributes)
        @add_attributes = attributes
      end

      def remove_attributes(attributes)
        @remove_attributes = attributes
      end

      def migrate!
        raise "#{self.class.name} did not implement migrate!"
      end

      protected
      def prepare_params!(attribute=nil)
        @params.keys.each{|k| error("unknown parameter: #{k}") unless ALLOWED_PARAMS.include? k}
      end

      def migrate_params!(attribute)
        attribute.add_attributes(@add_attributes) if @add_attributes
        attribute.remove_attributes(@remove_attributes) if @remove_attributes
        if @attributes
          previous_attributes = attribute.attributes
          attribute.remove_attributes(previous_attributes)
          attribute.add_attributes(@attributes)
        end
        @params.each{|k,v|attribute.set(k,v)}
        attribute.save!
      end
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
infopark_reactor-1.26.1 lib/reactor/plans/common_attribute_group.rb
infopark_reactor-1.26.0 lib/reactor/plans/common_attribute_group.rb
infopark_reactor-1.25.2 lib/reactor/plans/common_attribute_group.rb
infopark_reactor-1.25.1 lib/reactor/plans/common_attribute_group.rb
infopark_reactor-1.25.0 lib/reactor/plans/common_attribute_group.rb
infopark_reactor-1.24.1 lib/reactor/plans/common_attribute_group.rb
infopark_reactor-1.24.0 lib/reactor/plans/common_attribute_group.rb
infopark_reactor-1.23.1 lib/reactor/plans/common_attribute_group.rb
infopark_reactor-1.23.0 lib/reactor/plans/common_attribute_group.rb
infopark_reactor-1.23.0.beta2 lib/reactor/plans/common_attribute_group.rb
infopark_reactor-1.22.6 lib/reactor/plans/common_attribute_group.rb
infopark_reactor-1.22.5 lib/reactor/plans/common_attribute_group.rb
infopark_reactor-1.22.4 lib/reactor/plans/common_attribute_group.rb
infopark_reactor-1.22.3 lib/reactor/plans/common_attribute_group.rb
infopark_reactor-1.22.2 lib/reactor/plans/common_attribute_group.rb
infopark_reactor-1.22.1 lib/reactor/plans/common_attribute_group.rb
infopark_reactor-1.22.0 lib/reactor/plans/common_attribute_group.rb
infopark_reactor-1.21.0 lib/reactor/plans/common_attribute_group.rb
infopark_reactor-1.20.4 lib/reactor/plans/common_attribute_group.rb
infopark_reactor-1.20.3 lib/reactor/plans/common_attribute_group.rb