Sha256: fed2ade517a3e863802794c90f69fc9f71f1332dc01c2a08740a111027b05019

Contents?: true

Size: 1.06 KB

Versions: 1

Compression:

Stored size: 1.06 KB

Contents

require 'yaml'

module ChangeManager
  class Change < ActiveRecord::Base
  	validates :change_type, :owner, :target, presence: true

  	def self.new_change(owner, change_type, context, target, cancelled = false)
  		# needs a spec
  		# create object in db
  		# return object id
  		foo = self.create({
        owner: owner, 
        change_type: change_type, 
        context: context, 
        target: target, 
        cancelled: cancelled,
        notified: false
        })
  		foo.id
  	end

    def cancel
      self.cancelled = true
      self.save
    end

    def notify
      self.notified = true
      self.save
    end

    def cancelled?
      self.cancelled
    end

    def notified?
      self.notified
    end

    def inverse_of?(possible_inverse_change)
      @change_types ||= YAML.load_file(File.join(ChangeManager::Engine.root, 'config/change_types.yaml'))
      if self.context == possible_inverse_change.context
        self.change_type == @change_types[possible_inverse_change.change_type]['inverse']
      else 
        false
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
change_manager-0.0.9 app/models/change_manager/change.rb