Module: Subledger::Store
- Included in:
- Api::Store
- Defined in:
- lib/subledger/store.rb,
lib/subledger/store/api/store.rb,
lib/subledger/store/api/errors.rb,
lib/subledger/store/api/roles/post.rb,
lib/subledger/store/api/roles/read.rb,
lib/subledger/store/api/roles/create.rb,
lib/subledger/store/api/roles/update.rb,
lib/subledger/store/api/roles/archive.rb,
lib/subledger/store/api/roles/balance.rb,
lib/subledger/store/api/roles/collect.rb,
lib/subledger/store/api/roles/reports.rb,
lib/subledger/store/api/roles/activate.rb,
lib/subledger/store/api/roles/progress.rb,
lib/subledger/store/api/roles/categories.rb,
lib/subledger/store/api/roles/create_line.rb,
lib/subledger/store/api/roles/create_and_post.rb,
lib/subledger/store/api/roles/create_identity.rb,
lib/subledger/store/api/roles/first_and_last_line.rb
Defined Under Namespace
Modules: Api
Classes: ActivateError, ArchiveError, AttachError, BalanceError, BucketValidatorError, CategoryError, CollectError, CreateError, CreateLineError, DeleteError, DetachError, FirstAndLastLineError, PostError, ProgressError, ReadError, ReportError, UpdateConflictError, UpdateError, UpdateNotFoundError
Instance Attribute Summary collapse
Instance Method Summary
collapse
Instance Attribute Details
#auth_key ⇒ Object
Returns the value of attribute auth_key.
24
25
26
|
# File 'lib/subledger/store.rb', line 24
def auth_key
@auth_key
end
|
Instance Method Details
#add_initial_controls_for(org) ⇒ Object
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
# File 'lib/subledger/store.rb', line 95
def add_initial_controls_for org
client = org.client
key = read client.keys :id => auth_key.id
identity = key.identity
create client.active_controls :org => org,
:identity => identity,
:verbs => 'GET|PATCH',
:path => "/#{API_VERSION}/orgs/#{org.id}",
:mode => :allow
create client.active_controls :org => org,
:identity => identity,
:verbs => 'POST|GET|PATCH',
:path => "/#{API_VERSION}/orgs/#{org.id}/*",
:mode => :allow
end
|
#add_initial_controls_to(identity) ⇒ Object
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
# File 'lib/subledger/store.rb', line 123
def add_initial_controls_to identity
client = identity.client
client.active_controls.create :identity => identity,
:verbs => 'GET|PATCH',
:path => "/#{API_VERSION}/identities/#{identity.id}",
:mode => :allow
client.active_controls.create :identity => identity,
:verbs => 'GET|POST',
:path => "/#{API_VERSION}/identities/#{identity.id}/*",
:mode => :allow
client.active_controls.create :identity => identity,
:verbs => 'POST',
:path => "/#{API_VERSION}/orgs",
:mode => :allow
end
|
#add_key_to(identity) ⇒ Object
117
118
119
120
121
|
# File 'lib/subledger/store.rb', line 117
def add_key_to identity
key = identity.client.active_keys :identity => identity
create key
end
|
#attributes ⇒ Object
32
33
34
|
# File 'lib/subledger/store.rb', line 32
def attributes
{ :auth_key => auth_key }
end
|
#backup_exists?(anchor) ⇒ Boolean
81
82
83
|
# File 'lib/subledger/store.rb', line 81
def backup_exists? anchor
Celluloid::Actor[:backup_creators].exists? :anchor => anchor
end
|
#collect(args) ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/subledger/store.rb', line 36
def collect args
collection_name = args[:collection_name]
action = args[:action]
limit = args[:limit]
no_balances = args[:no_balances]
begin
if limit.nil? or limit < 1 or limit > 100
raise CollectError, ':limit must be 1-100'
end
collected = send action, args
if collection_name == :account_lines and not collected.empty?
if no_balances
collected.each do |line|
line.send :balance=, nil
end
else
args.merge! :account_lines => collected
set_account_line_balances args
end
end
collected
rescue Exception => e
raise CollectError, "Unable to collect #{collection_name}: #{e}"
end
end
|
#create_backup(anchor) ⇒ Object
75
76
77
78
79
|
# File 'lib/subledger/store.rb', line 75
def create_backup anchor
Celluloid::Actor[:backup_creators].async.create :anchor => anchor
anchor
end
|
#create_identity(identity) ⇒ Object
85
86
87
88
89
90
91
92
93
|
# File 'lib/subledger/store.rb', line 85
def create_identity identity
create identity
key = add_key_to identity
add_initial_controls_to identity
return identity, key
end
|
#first_and_last_line(args) ⇒ Object
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
# File 'lib/subledger/store.rb', line 142
def first_and_last_line args
account = args[:account]
begin
lines = [ ]
lines += first_or_last_line( args.merge! :effective_at => first_second,
:action => :starting )
lines += first_or_last_line( args.merge! :effective_at => last_second,
:action => :ending )
end while lines.length == 1 and sleep 0.025
lines
end
|
#initialize(args) ⇒ Object
26
27
28
29
30
|
# File 'lib/subledger/store.rb', line 26
def initialize args
@auth_key = args[:auth_key]
setup
end
|
#raise_unless_bucket_name_valid(args) ⇒ Object
67
68
69
70
71
72
73
|
# File 'lib/subledger/store.rb', line 67
def raise_unless_bucket_name_valid args
bucket_name = args[:bucket_name]
unless bucket_name.nil?
Celluloid::Actor[:backup_bucket_validators].validate args
end
end
|