Class: Subledger::Domain::ActiveReport

Inherits:
Report
  • Object
show all
Defined in:
lib/subledger/domain/report.rb

Defined Under Namespace

Classes: Entity

Instance Attribute Summary

Attributes inherited from Report

#book

Attributes included from Roles::Versionable

#version

Attributes included from Roles::Storable

#client, #store

Attributes included from Roles::Identifiable

#id

Attributes included from Roles::Describable

#description, #reference

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Report

active_klass, archived_klass, #initialize, patch_keys, post_keys, root_klass

Methods included from Roles::Restable

#patch_hash, #post_hash, #serializable_hash, #to_json

Methods included from Roles::Archivable

#archive

Methods included from Roles::Activatable

#activate

Methods included from Roles::Collectable

included

Methods included from Roles::Updatable

included, #update

Methods included from Roles::Readable

included, #read

Methods included from Roles::Creatable

#create, included

Methods included from Roles::Versionable

included

Methods included from Roles::Storable

raise_unless_creatable

Methods included from Roles::Describable

raise_unless_creatable

Methods included from Roles::Attributable

#attributes

Methods included from Subledger::Domain

#==, #collection_name, #entity_name, included, #to_s

Constructor Details

This class inherits a constructor from Subledger::Domain::Report

Class Method Details

.sub_klassesObject



109
110
111
# File 'lib/subledger/domain/report.rb', line 109

def self.sub_klasses
  [ active_klass ]
end

Instance Method Details

#attach(args) ⇒ Object



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/subledger/domain/report.rb', line 121

def attach args
  validate_attach args

  category = args[:category]
  parent   = args[:parent]

  if category.nil? or category.id.nil?
    raise ReportError, ':category is required and must have an id'
  end

  if not parent.nil? and parent.id.nil?
    raise ReportError, ':parent must have an id'
  end

  begin
    store.attach_category_to_report :report   => self,
                                    :category => category,
                                    :parent   => parent
  rescue Store::AttachError => e
    raise ReportError, e
  end

  category
end

#categories(&block) ⇒ Object



113
114
115
116
117
118
119
# File 'lib/subledger/domain/report.rb', line 113

def categories &block
  begin
    store.collect_categories_for_report self, &block
  rescue Store::CollectError => e
    raise ReportError, e
  end
end

#detach(args) ⇒ Object



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/subledger/domain/report.rb', line 146

def detach args
  category = args[:category]

  if category.nil? or category.id.nil?
    raise ReportError, ':category is required and must have an id'
  end

  begin
    store.detach_category_from_report :report   => self,
                                      :category => category
  rescue Store::DetachError => e
    raise ReportError, e
  end

  category
end

#render(args) ⇒ Object



163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/subledger/domain/report.rb', line 163

def render args
  at = args[:at]

  if at.nil? or not at.kind_of? Time
    raise ReportError, ':at is required and must be a Time'
  end

  building_report_rendering = client.building_report_rendering :effective_at => at,
                                                               :report       => self

  store.render args.merge! :building_report_rendering => building_report_rendering
end