class Subledger::Domain::Category

Constants

ACCEPTABLE_NORMAL_BALANCES

Attributes

book[R]
normal_balance[RW]

Public Class Methods

active_klass() click to toggle source
# File lib/subledger/domain/category.rb, line 45
def self.active_klass
  ActiveCategory
end
archived_klass() click to toggle source
# File lib/subledger/domain/category.rb, line 49
def self.archived_klass
  ArchivedCategory
end
new(args) click to toggle source
# File lib/subledger/domain/category.rb, line 53
def initialize args
  describable args
  identifiable args
  storable args
  versionable args

  @book           = args[:book]
  @normal_balance = args[:normal_balance]
end
patch_keys() click to toggle source
# File lib/subledger/domain/category.rb, line 33
def self.patch_keys
  [ :id, :description, :reference, :normal_balance, :version ]
end
post_keys() click to toggle source
# File lib/subledger/domain/category.rb, line 29
def self.post_keys
  [ :description, :reference, :normal_balance ]
end
root_klass() click to toggle source
# File lib/subledger/domain/category.rb, line 37
def self.root_klass
  Category
end
sub_klasses() click to toggle source
# File lib/subledger/domain/category.rb, line 41
def self.sub_klasses
  [ active_klass, archived_klass ]
end

Private Class Methods

raise_unless_creatable(args) click to toggle source
# File lib/subledger/domain/category.rb, line 93
def self.raise_unless_creatable args

  book = args[:book]

  if book.nil? or not book.kind_of? Book
    raise CategoryError, ':book is required and must be a Book'
  elsif UUID.invalid? book.id
    raise CategoryError, ':book must have a valid :id'
  end

  normal_balance = args[:normal_balance]

  if normal_balance.nil? or not ACCEPTABLE_NORMAL_BALANCES.include? normal_balance
    raise CategoryError, ":normal_balance is required and must be one of #{ACCEPTABLE_NORMAL_BALANCES.join(', ')}"
  end
end

Public Instance Methods

accounts(&block) click to toggle source
# File lib/subledger/domain/category.rb, line 63
def accounts &block
  begin
    store.collect_accounts_for_category self, &block
  rescue Store::CollectError => e
    raise CategoryError, e
  end
end