Sha256: 8e6ed25872580dcb658c3308e7de936bb0e34e773043f9b81d9e47acfb4bd8f2

Contents?: true

Size: 1.06 KB

Versions: 4

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: nil
        })
  		foo.id
  	end

    def cancel
      self.cancelled = true
      self.save
    end

    def notify
      self.notified = DateTime.now
      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

4 entries across 4 versions & 1 rubygems

Version Path
change_manager-0.1.5 app/models/change_manager/change.rb
change_manager-0.1.2 app/models/change_manager/change.rb
change_manager-0.1.1 app/models/change_manager/change.rb
change_manager-0.1.0 app/models/change_manager/change.rb