class Reactor::Plans::CommonAttributeGroup

Constants

ALLOWED_PARAMS

Public Class Methods

new() click to toggle source
# File lib/reactor/plans/common_attribute_group.rb, line 8
def initialize
  @params = {}
end

Public Instance Methods

add_attributes(attributes) click to toggle source
# File lib/reactor/plans/common_attribute_group.rb, line 21
def add_attributes(attributes)
  @add_attributes = attributes
end
migrate!() click to toggle source
# File lib/reactor/plans/common_attribute_group.rb, line 29
def migrate!
  raise "#{self.class.name} did not implement migrate!"
end
remove_attributes(attributes) click to toggle source
# File lib/reactor/plans/common_attribute_group.rb, line 25
def remove_attributes(attributes)
  @remove_attributes = attributes
end
set(key,value) click to toggle source
# File lib/reactor/plans/common_attribute_group.rb, line 12
def set(key,value)
  key = key.to_sym
  if key == :attributes
    @attributes = value
  else
    @params[key.to_sym] = value
  end
end

Protected Instance Methods

migrate_params!(attribute) click to toggle source
# File lib/reactor/plans/common_attribute_group.rb, line 38
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
prepare_params!(attribute=nil) click to toggle source
# File lib/reactor/plans/common_attribute_group.rb, line 34
def prepare_params!(attribute=nil)
  @params.keys.each{|k| error("unknown parameter: #{k}") unless ALLOWED_PARAMS.include? k}
end