Sha256: 0aa5e0793446176ff0f06132992278cfa9a4b8a9f2127df13639f602ab600e4a

Contents?: true

Size: 945 Bytes

Versions: 1

Compression:

Stored size: 945 Bytes

Contents

require 'yaml'

module ChangeManager
  class Change < ActiveRecord::Base
  	validates :change_type, :owner, :target, :context, 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
        })
  		foo.id
  	end

    def cancel
      self.cancelled = true
      self.save
    end

    def cancelled?
      self.cancelled
    end

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

Version data entries

1 entries across 1 versions & 1 rubygems

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