Sha256: 02865458f9fefa99622d69b48d8fdde4b5323f1081178355bf1d7e1aaad2d637

Contents?: true

Size: 1.42 KB

Versions: 1

Compression:

Stored size: 1.42 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 is_group_change?
      self.change_type == 'added_to_group' || self.change_type == 'removed_from_group'
    end

    def is_delegate_change?
      self.change_type == 'added_as_delegate' || self.change_type == 'removed_as_delegate'
    end

    def is_editor_change?
      self.change_type == 'added_as_editor' || self.change_type == 'removed_as_editor'
    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.2.0 app/models/change_manager/change.rb