lockstep_rails 0.3.22
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +216 -0
- data/Rakefile +31 -0
- data/app/assets/config/lockstep_rails_manifest.js +0 -0
- data/app/concepts/lockstep/active_records/association.rb +78 -0
- data/app/concepts/lockstep/api_record.rb +1118 -0
- data/app/concepts/lockstep/api_records/scopes.rb +20 -0
- data/app/concepts/lockstep/client.rb +162 -0
- data/app/concepts/lockstep/error.rb +50 -0
- data/app/concepts/lockstep/exceptions.rb +4 -0
- data/app/concepts/lockstep/query.rb +409 -0
- data/app/concepts/lockstep/query_methods.rb +75 -0
- data/app/concepts/lockstep/relation_array.rb +100 -0
- data/app/helpers/types.rb +3 -0
- data/app/models/lockstep/account.rb +15 -0
- data/app/models/lockstep/connection.rb +19 -0
- data/app/models/lockstep/contact.rb +9 -0
- data/app/models/lockstep/customer_summary.rb +6 -0
- data/app/models/lockstep/invoice.rb +7 -0
- data/app/models/lockstep/invoice_summary.rb +6 -0
- data/app/models/lockstep/invoices/address.rb +24 -0
- data/app/models/lockstep/note.rb +7 -0
- data/app/models/lockstep/payment.rb +7 -0
- data/app/models/lockstep/payment_summary.rb +6 -0
- data/app/models/lockstep/user.rb +10 -0
- data/app/platform_api/model_template.rb.erb +27 -0
- data/app/platform_api/schema/action_result.rb +15 -0
- data/app/platform_api/schema/activity.rb +141 -0
- data/app/platform_api/schema/activity_fetch_result.rb +26 -0
- data/app/platform_api/schema/activity_stream_item.rb +58 -0
- data/app/platform_api/schema/activity_x_ref.rb +37 -0
- data/app/platform_api/schema/aging.rb +24 -0
- data/app/platform_api/schema/api_key.rb +71 -0
- data/app/platform_api/schema/api_key_fetch_result.rb +26 -0
- data/app/platform_api/schema/app_enrollment.rb +88 -0
- data/app/platform_api/schema/app_enrollment_custom_field.rb +67 -0
- data/app/platform_api/schema/app_enrollment_custom_field_fetch_result.rb +26 -0
- data/app/platform_api/schema/app_enrollment_fetch_result.rb +26 -0
- data/app/platform_api/schema/application.rb +89 -0
- data/app/platform_api/schema/application_fetch_result.rb +26 -0
- data/app/platform_api/schema/ar_aging_header_info.rb +47 -0
- data/app/platform_api/schema/ar_header_info.rb +118 -0
- data/app/platform_api/schema/assembly.rb +68 -0
- data/app/platform_api/schema/at_risk_invoice_summary.rb +90 -0
- data/app/platform_api/schema/at_risk_invoice_summary_fetch_result.rb +26 -0
- data/app/platform_api/schema/attachment.rb +92 -0
- data/app/platform_api/schema/attachment_fetch_result.rb +26 -0
- data/app/platform_api/schema/attachment_header_info.rb +41 -0
- data/app/platform_api/schema/batch_sync.rb +18 -0
- data/app/platform_api/schema/bulk_currency_conversion.rb +19 -0
- data/app/platform_api/schema/cashflow_report.rb +35 -0
- data/app/platform_api/schema/code_definition.rb +58 -0
- data/app/platform_api/schema/code_definition_fetch_result.rb +26 -0
- data/app/platform_api/schema/company.rb +243 -0
- data/app/platform_api/schema/company_fetch_result.rb +26 -0
- data/app/platform_api/schema/company_sync.rb +142 -0
- data/app/platform_api/schema/connector_info.rb +27 -0
- data/app/platform_api/schema/constructor_info.rb +128 -0
- data/app/platform_api/schema/contact.rb +148 -0
- data/app/platform_api/schema/contact_fetch_result.rb +26 -0
- data/app/platform_api/schema/contact_sync.rb +109 -0
- data/app/platform_api/schema/country.rb +62 -0
- data/app/platform_api/schema/country_fetch_result.rb +26 -0
- data/app/platform_api/schema/credit_memo_applied.rb +104 -0
- data/app/platform_api/schema/credit_memo_applied_fetch_result.rb +26 -0
- data/app/platform_api/schema/credit_memo_applied_sync.rb +67 -0
- data/app/platform_api/schema/credit_memo_invoice.rb +77 -0
- data/app/platform_api/schema/currency.rb +31 -0
- data/app/platform_api/schema/currency_fetch_result.rb +26 -0
- data/app/platform_api/schema/currency_rate.rb +28 -0
- data/app/platform_api/schema/custom_attribute_data.rb +18 -0
- data/app/platform_api/schema/custom_attribute_named_argument.rb +24 -0
- data/app/platform_api/schema/custom_attribute_typed_argument.rb +16 -0
- data/app/platform_api/schema/custom_field_definition.rb +76 -0
- data/app/platform_api/schema/custom_field_definition_fetch_result.rb +26 -0
- data/app/platform_api/schema/custom_field_sync.rb +71 -0
- data/app/platform_api/schema/custom_field_value.rb +75 -0
- data/app/platform_api/schema/custom_field_value_fetch_result.rb +26 -0
- data/app/platform_api/schema/customer_details.rb +98 -0
- data/app/platform_api/schema/customer_details_payment.rb +60 -0
- data/app/platform_api/schema/customer_summary.rb +88 -0
- data/app/platform_api/schema/customer_summary_fetch_result.rb +26 -0
- data/app/platform_api/schema/daily_sales_outstanding_report.rb +25 -0
- data/app/platform_api/schema/developer_account_submit.rb +23 -0
- data/app/platform_api/schema/email.rb +160 -0
- data/app/platform_api/schema/email_fetch_result.rb +26 -0
- data/app/platform_api/schema/erp.rb +23 -0
- data/app/platform_api/schema/erp_fetch_result.rb +26 -0
- data/app/platform_api/schema/erp_info.rb +18 -0
- data/app/platform_api/schema/erp_info_data.rb +23 -0
- data/app/platform_api/schema/event_info.rb +59 -0
- data/app/platform_api/schema/exception.rb +41 -0
- data/app/platform_api/schema/field_info.rb +105 -0
- data/app/platform_api/schema/financial_account.rb +90 -0
- data/app/platform_api/schema/financial_account_balance_history.rb +90 -0
- data/app/platform_api/schema/financial_account_balance_history_fetch_result.rb +26 -0
- data/app/platform_api/schema/financial_account_fetch_result.rb +26 -0
- data/app/platform_api/schema/financial_year_setting.rb +74 -0
- data/app/platform_api/schema/financial_year_setting_fetch_result.rb +26 -0
- data/app/platform_api/schema/invite.rb +25 -0
- data/app/platform_api/schema/invite_data.rb +18 -0
- data/app/platform_api/schema/invite_submit.rb +15 -0
- data/app/platform_api/schema/invoice.rb +226 -0
- data/app/platform_api/schema/invoice_address.rb +97 -0
- data/app/platform_api/schema/invoice_fetch_result.rb +29 -0
- data/app/platform_api/schema/invoice_history.rb +188 -0
- data/app/platform_api/schema/invoice_history_fetch_result.rb +26 -0
- data/app/platform_api/schema/invoice_line.rb +142 -0
- data/app/platform_api/schema/invoice_line_sync.rb +208 -0
- data/app/platform_api/schema/invoice_payment_detail.rb +65 -0
- data/app/platform_api/schema/invoice_summary.rb +85 -0
- data/app/platform_api/schema/invoice_summary_fetch_result.rb +26 -0
- data/app/platform_api/schema/invoice_sync.rb +280 -0
- data/app/platform_api/schema/lead.rb +32 -0
- data/app/platform_api/schema/member_info.rb +36 -0
- data/app/platform_api/schema/method_base.rb +128 -0
- data/app/platform_api/schema/method_info.rb +137 -0
- data/app/platform_api/schema/module.rb +44 -0
- data/app/platform_api/schema/module_handle.rb +15 -0
- data/app/platform_api/schema/note.rb +72 -0
- data/app/platform_api/schema/note_fetch_result.rb +26 -0
- data/app/platform_api/schema/parameter_info.rb +64 -0
- data/app/platform_api/schema/payment.rb +147 -0
- data/app/platform_api/schema/payment_applied.rb +95 -0
- data/app/platform_api/schema/payment_applied_fetch_result.rb +26 -0
- data/app/platform_api/schema/payment_applied_sync.rb +74 -0
- data/app/platform_api/schema/payment_detail.rb +110 -0
- data/app/platform_api/schema/payment_detail_fetch_result.rb +26 -0
- data/app/platform_api/schema/payment_detail_header.rb +43 -0
- data/app/platform_api/schema/payment_fetch_result.rb +26 -0
- data/app/platform_api/schema/payment_summary.rb +79 -0
- data/app/platform_api/schema/payment_summary_fetch_result.rb +26 -0
- data/app/platform_api/schema/payment_sync.rb +112 -0
- data/app/platform_api/schema/problem_details.rb +31 -0
- data/app/platform_api/schema/property_info.rb +60 -0
- data/app/platform_api/schema/provisioning.rb +28 -0
- data/app/platform_api/schema/provisioning_finalize_request.rb +28 -0
- data/app/platform_api/schema/provisioning_response.rb +42 -0
- data/app/platform_api/schema/risk_rate.rb +57 -0
- data/app/platform_api/schema/runtime_field_handle.rb +13 -0
- data/app/platform_api/schema/runtime_method_handle.rb +13 -0
- data/app/platform_api/schema/runtime_type_handle.rb +13 -0
- data/app/platform_api/schema/state.rb +22 -0
- data/app/platform_api/schema/state_fetch_result.rb +26 -0
- data/app/platform_api/schema/status.rb +72 -0
- data/app/platform_api/schema/struct_layout_attribute.rb +16 -0
- data/app/platform_api/schema/sync_entity_result.rb +34 -0
- data/app/platform_api/schema/sync_request.rb +71 -0
- data/app/platform_api/schema/sync_request_fetch_result.rb +26 -0
- data/app/platform_api/schema/sync_submit.rb +15 -0
- data/app/platform_api/schema/test_argument_exception.rb +41 -0
- data/app/platform_api/schema/test_timeout_exception.rb +41 -0
- data/app/platform_api/schema/transfer_owner.rb +16 -0
- data/app/platform_api/schema/transfer_owner_submit.rb +15 -0
- data/app/platform_api/schema/type.rb +278 -0
- data/app/platform_api/schema/type_info.rb +287 -0
- data/app/platform_api/schema/uri.rb +15 -0
- data/app/platform_api/schema/user_account.rb +152 -0
- data/app/platform_api/schema/user_account_fetch_result.rb +26 -0
- data/app/platform_api/schema/user_role.rb +50 -0
- data/app/platform_api/schema/user_role_fetch_result.rb +26 -0
- data/app/platform_api/schema/webhook.rb +96 -0
- data/app/platform_api/schema/webhook_fetch_result.rb +26 -0
- data/app/platform_api/schema/webhook_history_table_storage.rb +64 -0
- data/app/platform_api/schema/webhook_history_table_storage_fetch_result.rb +26 -0
- data/app/platform_api/swagger.json +22056 -0
- data/config/routes.rb +2 -0
- data/lib/lockstep_rails/engine.rb +4 -0
- data/lib/lockstep_rails/version.rb +3 -0
- data/lib/lockstep_rails.rb +5 -0
- data/lib/tasks/lockstep_rails_tasks.rake +4 -0
- data/lib/tasks/update_api_schema.rake +159 -0
- metadata +230 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9061d2c0869b6f4178fcd240f0e1337b3cbdc62500d9c8922f9b6c73812359da
|
4
|
+
data.tar.gz: 2ca982684af590994f83a992494e527ef79a29b66102f27fe7021c4e39312e89
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b7e815ea5d2b411df62b258454d57437cd569181d8da0a3f2fb62b7666aa45dad0181845631e7d0d6f1c0ac0e517dbb00aba1a20075e444bbb94897eb8be5dea
|
7
|
+
data.tar.gz: 107df8a7b2031c9bd00170a64eb0bb0b98e59f3332d3a8bed509b49883b94c2a102ed01db8efd73b8ccecb8f1227162d64950d0d01787c3a3389c6f40cfee4c2
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2022 Vivek AG
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,216 @@
|
|
1
|
+
# Lockstep
|
2
|
+
A financial service SDK for rails for innovative accounting solutions providers.
|
3
|
+
|
4
|
+
### Who are we?
|
5
|
+
Lockstep automates accounting workflows to improve your operational efficiency and cash flow. Accelerate payments through automated customer communications, enhanced collections activity management, and innovative forecasting and reporting.
|
6
|
+
|
7
|
+
### lockstep_rails
|
8
|
+
lockstep_rails makes it easy to interact with lockstep.io's REST API. It adheres to the ActiveRecord pattern. LockstepRails is fully ActiveModel compliant, meaning you can use validations and Rails forms.
|
9
|
+
|
10
|
+
Ruby/Rails developers should feel right at home.
|
11
|
+
|
12
|
+
If you're used to `Lockstep::Contact.create(:email_address => "test@emaildomain.com")`, then this is for you.
|
13
|
+
|
14
|
+
### Features
|
15
|
+
* ActiveRecord-like API, almost no learning curve
|
16
|
+
* Validations
|
17
|
+
* Rails forms and scaffolds **just work**
|
18
|
+
|
19
|
+
## Installation
|
20
|
+
Add this line to your application's Gemfile:
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
gem 'lockstep_rails'
|
24
|
+
```
|
25
|
+
|
26
|
+
And then execute:
|
27
|
+
```bash
|
28
|
+
$ bundle
|
29
|
+
```
|
30
|
+
|
31
|
+
Or install it yourself as:
|
32
|
+
```bash
|
33
|
+
$ gem install lockstep_rails
|
34
|
+
```
|
35
|
+
|
36
|
+
## License
|
37
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
38
|
+
|
39
|
+
# Usage
|
40
|
+
|
41
|
+
### Available Records
|
42
|
+
* Lockstep::Contact
|
43
|
+
* Lockstep::Connection
|
44
|
+
* Lockstep::Account
|
45
|
+
* Lockstep::User
|
46
|
+
* Lockstep::Note
|
47
|
+
* Lockstep::Invoice
|
48
|
+
* Lockstep::InvoiceSummary
|
49
|
+
* Lockstep::CustomerSummary
|
50
|
+
* Lockstep::Payments
|
51
|
+
* Lockstep::PaymentSummary
|
52
|
+
|
53
|
+
## ActiveModel Interfaces
|
54
|
+
|
55
|
+
`lockstep_rails` supports the standard CRUD interface of ActiveRecord.
|
56
|
+
|
57
|
+
### Create
|
58
|
+
You can create a record by calling `new` or `create`
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
Lockstep::Contact.create(email_address: "inbox@companyemail.com")
|
62
|
+
```
|
63
|
+
|
64
|
+
You can create records from associations as well. This will automatically association the relationship with the parent record
|
65
|
+
```ruby
|
66
|
+
connection = Lockstep::Connection.find(company_id: "17544da8-7be8-4ee2-8c62-cbd81428c68b")
|
67
|
+
connection.contacts.create(email_address: "inbox@companyemail.com")
|
68
|
+
```
|
69
|
+
|
70
|
+
### Update
|
71
|
+
Similar to ActiveRecord, you can update a record by calling `update`, `update_attributes` or `update_attribute`
|
72
|
+
|
73
|
+
Examples:
|
74
|
+
```ruby
|
75
|
+
connection = Lockstep::Connection.find(company_id: "17544da8-7be8-4ee2-8c62-cbd81428c68b")
|
76
|
+
connection.update(company_name: "New name")
|
77
|
+
|
78
|
+
# Or
|
79
|
+
connection.update_attributes(company_name: "New name")
|
80
|
+
|
81
|
+
# Or
|
82
|
+
connection.update_attribute(:company_name, "New name")
|
83
|
+
```
|
84
|
+
|
85
|
+
### Find
|
86
|
+
Similar to ActiveRecord, you can find a record by calling `find`, `find_by` or `find_by_company_id`
|
87
|
+
|
88
|
+
Examples:
|
89
|
+
```ruby
|
90
|
+
connection = Lockstep::Connection.find(company_id: "17544da8-7be8-4ee2-8c62-cbd81428c68b")
|
91
|
+
connection.update(company_name: "New name")
|
92
|
+
|
93
|
+
# Or
|
94
|
+
connection.update_attributes(company_name: "New name")
|
95
|
+
|
96
|
+
# Or
|
97
|
+
connection.update_attribute(:company_name, "New name")
|
98
|
+
```
|
99
|
+
|
100
|
+
### Where
|
101
|
+
Similar to ActiveRecord, you can search for records by calling `where`.
|
102
|
+
|
103
|
+
Unless you are accessing the record via `first`, you will have to call `execute` to fetch the records
|
104
|
+
|
105
|
+
Examples:
|
106
|
+
```ruby
|
107
|
+
Lockstep::Connection.where(status: "Active").execute
|
108
|
+
```
|
109
|
+
|
110
|
+
#### Chaining
|
111
|
+
You can chain queries while calling where.
|
112
|
+
|
113
|
+
```ruby
|
114
|
+
Lockstep::Connection.where(status: "Active").where(default_currency_code: "USD").execute
|
115
|
+
```
|
116
|
+
|
117
|
+
#### OR Query
|
118
|
+
You can build an or query by calling `or`
|
119
|
+
|
120
|
+
```ruby
|
121
|
+
Lockstep::Connection.where(status: "Active").or(Lockstep::Connection.where(default_currency_code: "USD")).execute
|
122
|
+
```
|
123
|
+
|
124
|
+
#### Advanced Queries
|
125
|
+
[Searchlight](https://developer.lockstep.io/docs/querying-with-searchlight) supports building complex comparisons in the query.
|
126
|
+
|
127
|
+
| Suffice | Searchlight Query | Example |
|
128
|
+
|--------------|-----------------------|---------------------------------------------------|
|
129
|
+
| _eq | Equals | where(name_eq: "Test Name") |
|
130
|
+
| _gt | Greater Than | where(amount_gt: 100) |
|
131
|
+
| _ge | Greater Than Or Equal | where(amount_ge: 100) |
|
132
|
+
| _lt | Less Than | where(amount_lt: 100) |
|
133
|
+
| _le | Less Than Or Equal | where(amount_le: 100) |
|
134
|
+
| _ne | Not Equal | where(name_ne: "tak") |
|
135
|
+
| _in | IN | where(name_in: ["tik", "tok"]) |
|
136
|
+
| _contains | CONTAINS | where(name_contains: "kit") |
|
137
|
+
| _starts_with | STARTSWITH | where(name_starts_with: "tik") |
|
138
|
+
| _ends_with | ENDSWITH | where(name_ends_with: "tok") |
|
139
|
+
| _is | IS | where(name_is: nil) where(name_is: "NOT NULL") |
|
140
|
+
|
141
|
+
#### Searchlight Queries
|
142
|
+
Using the rails standard queries generates searchlight compatible queries.
|
143
|
+
if you wish, you can always write raw [Searchlight](https://developer.lockstep.io/docs/querying-with-searchlight) queries by passing a string in the where block
|
144
|
+
|
145
|
+
```ruby
|
146
|
+
Lockstep::Connection.where("isActive is true OR default_currency_code in ('USD', 'INR')").execute
|
147
|
+
```
|
148
|
+
|
149
|
+
### Count
|
150
|
+
You can fetch the count of available records by calling `count`
|
151
|
+
|
152
|
+
```ruby
|
153
|
+
Lockstep::Connection.count
|
154
|
+
# 1000
|
155
|
+
|
156
|
+
Lockstep::Connection.where(status: "Active").count
|
157
|
+
# 100
|
158
|
+
```
|
159
|
+
|
160
|
+
### Limit
|
161
|
+
You can limit the number of records being fetched by passing `limit`
|
162
|
+
|
163
|
+
The default limit is 200.
|
164
|
+
|
165
|
+
```ruby
|
166
|
+
Lockstep::Connection.limit(100).execute
|
167
|
+
|
168
|
+
Lockstep::Connection.where(status: "Active").limit(100).execute
|
169
|
+
```
|
170
|
+
|
171
|
+
### Pagination
|
172
|
+
You can paginate the records by passing the `page`
|
173
|
+
|
174
|
+
```ruby
|
175
|
+
Lockstep::Connection.page(2).execute
|
176
|
+
|
177
|
+
Lockstep::Connection.where(status: "Active").limit(100).page(2).execute
|
178
|
+
```
|
179
|
+
|
180
|
+
## Adding relationships with ActiveRecord
|
181
|
+
If you would like to link the `Lockstep::ApiRecord` with an `ActiveRecord::Base`, you can do so by including `Lockstep::ActiveRecords::Association`
|
182
|
+
|
183
|
+
This gives you access to 2 methods for defining relationships
|
184
|
+
* lockstep_has_many
|
185
|
+
* lockstep_belongs_to
|
186
|
+
|
187
|
+
```ruby
|
188
|
+
class User < ActiveRecord::Base
|
189
|
+
include Lockstep::ActiveRecords::Association
|
190
|
+
|
191
|
+
lockstep_has_many :connections, class_name: "Lockstep::Connection", primary_key: 'company_id', foreign_key: "lockstep_company_id"
|
192
|
+
lockstep_belongs_to :account, class_name: "Lockstep::Account", primary_key: 'company_id', foreign_key: "lockstep_company_id"
|
193
|
+
|
194
|
+
end
|
195
|
+
```
|
196
|
+
|
197
|
+
#### Loader
|
198
|
+
You could define your own loader for fetching the records by passing a `loader` Proc
|
199
|
+
|
200
|
+
```ruby
|
201
|
+
class User < ActiveRecord::Base
|
202
|
+
include Lockstep::ActiveRecords::Association
|
203
|
+
|
204
|
+
lockstep_has_many :connections, class_name: "Lockstep::Connection", loader: -> (record) { Lockstep::Connection.where(is_active: true).where(company_id: record.lockstep_company_id) }
|
205
|
+
lockstep_belongs_to :account, class_name: "Lockstep::Account", loader: -> (record) { Lockstep::Account.where(is_active: true).first }
|
206
|
+
|
207
|
+
end
|
208
|
+
```
|
209
|
+
|
210
|
+
# Updating API Schema
|
211
|
+
|
212
|
+
To update the schema to the latest one on https://api.dev.lockstep.io/swagger/v1/swagger.json, run
|
213
|
+
|
214
|
+
```bash
|
215
|
+
bundle exec rake update_api_schema
|
216
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
begin
|
2
|
+
require "bundler/setup"
|
3
|
+
rescue LoadError
|
4
|
+
puts "You must `gem install bundler` and `bundle install` to run rake tasks"
|
5
|
+
end
|
6
|
+
|
7
|
+
require "rdoc/task"
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = "rdoc"
|
11
|
+
rdoc.title = "LockstepRails"
|
12
|
+
rdoc.options << "--line-numbers"
|
13
|
+
rdoc.rdoc_files.include("README.md")
|
14
|
+
rdoc.rdoc_files.include("lib/**/*.rb")
|
15
|
+
end
|
16
|
+
|
17
|
+
load "rails/tasks/statistics.rake"
|
18
|
+
|
19
|
+
require "bundler/gem_tasks"
|
20
|
+
|
21
|
+
require "rake/testtask"
|
22
|
+
|
23
|
+
Rake::TestTask.new(:test) do |t|
|
24
|
+
t.libs << "test"
|
25
|
+
t.pattern = "test/**/*_test.rb"
|
26
|
+
t.verbose = false
|
27
|
+
end
|
28
|
+
|
29
|
+
load "lib/tasks/update_api_schema.rake"
|
30
|
+
|
31
|
+
task default: :test
|
File without changes
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module Lockstep::ActiveRecords::Association
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
included do
|
5
|
+
|
6
|
+
end
|
7
|
+
|
8
|
+
class_methods do
|
9
|
+
def lockstep_has_many_relations
|
10
|
+
@lockstep_has_many_relations ||= {}
|
11
|
+
end
|
12
|
+
|
13
|
+
def lockstep_belongs_to_relations
|
14
|
+
@lockstep_belongs_to_relations ||= {}
|
15
|
+
end
|
16
|
+
|
17
|
+
def lockstep_has_many(attribute, class_name:, primary_key: 'lockstep_id', foreign_key: nil, polymorphic: nil, loader: nil)
|
18
|
+
lockstep_has_many_relations[attribute] = {
|
19
|
+
name: attribute, class_name: class_name, primary_key: primary_key,
|
20
|
+
foreign_key: foreign_key, polymorphic: polymorphic, loader: loader
|
21
|
+
}
|
22
|
+
|
23
|
+
define_method(attribute) do
|
24
|
+
return lockstep_attributes[attribute] unless lockstep_attributes[attribute].nil?
|
25
|
+
return nil if lockstep_loaded_associations.include?(attribute)
|
26
|
+
|
27
|
+
lockstep_loaded_associations << attribute
|
28
|
+
|
29
|
+
relation_config = self.class.lockstep_has_many_relations[attribute]
|
30
|
+
if relation_config[:loader].present?
|
31
|
+
lockstep_attributes[attribute] = relation_config[:loader].call(self)
|
32
|
+
else
|
33
|
+
query = { relation_config[:foreign_key] => self.send(relation_config[:primary_key]) }
|
34
|
+
if relation_config[:polymorphic]
|
35
|
+
polymorphic_config = Lockstep::RelationArray.has_many_polymorphic_attributes(self, relation_config[:polymorphic])
|
36
|
+
query.merge!(polymorphic_config)
|
37
|
+
end
|
38
|
+
related_objects = relation_config[:class_name].constantize.send(:where, query).execute
|
39
|
+
lockstep_attributes[attribute] = Lockstep::RelationArray.new self, related_objects, attribute, relation_config[:class_name]
|
40
|
+
end
|
41
|
+
|
42
|
+
lockstep_attributes[attribute]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def lockstep_belongs_to(attribute, class_name:, primary_key: nil, foreign_key: 'lockstep_id', polymorphic: nil, loader: nil)
|
47
|
+
lockstep_belongs_to_relations[attribute] = {
|
48
|
+
name: attribute, class_name: class_name, primary_key: primary_key,
|
49
|
+
foreign_key: foreign_key, polymorphic: polymorphic, loader: loader
|
50
|
+
}
|
51
|
+
|
52
|
+
define_method(attribute) do
|
53
|
+
return lockstep_attributes[attribute] unless lockstep_attributes[attribute].nil?
|
54
|
+
return nil if lockstep_loaded_associations.include?(attribute)
|
55
|
+
|
56
|
+
lockstep_loaded_associations << attribute
|
57
|
+
|
58
|
+
relation_config = self.class.lockstep_belongs_to_relations[attribute]
|
59
|
+
if relation_config[:loader].present?
|
60
|
+
lockstep_attributes[attribute] = relation_config[:loader].call(self)
|
61
|
+
else
|
62
|
+
lockstep_attributes[attribute] = relation_config[:class_name].constantize.send(:find_by, relation_config[:primary_key] => self.send(relation_config[:foreign_key]))
|
63
|
+
end
|
64
|
+
|
65
|
+
lockstep_attributes[attribute]
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def lockstep_loaded_associations
|
71
|
+
@loaded_associations ||= []
|
72
|
+
end
|
73
|
+
|
74
|
+
def lockstep_attributes
|
75
|
+
@lockstep_attributes ||= {}
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|