majorsilence_reporting 26.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +5 -0
- data/LICENSE-APACHE +201 -0
- data/LICENSE-BSD +9 -0
- data/LICENSE-MIT +9 -0
- data/README.md +254 -0
- data/lib/majorsilence_reporting/report.rb +93 -0
- data/lib/majorsilence_reporting/report_aot.rb +90 -0
- data/lib/majorsilence_reporting/report_native.rb +218 -0
- data/lib/majorsilence_reporting/version.rb +5 -0
- data/lib/majorsilence_reporting.rb +6 -0
- metadata +101 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: d0c20949e3b2c421c89e771936dc50e98082291cf6e11d145de122460ccf8853
|
|
4
|
+
data.tar.gz: b9ea34259b4746f52d222fdda1582a12e49b35c7b21017c4d0294c8eab720995
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 9af31caf85cf5eaf612009990b8a66fcd17c8e6be8195cab1662cee9813f11ad1a882d37815a7e81f91f5010df24f7840622d1d3f511849b396336d9f608898d
|
|
7
|
+
data.tar.gz: 7714eb5ca849b9044754c0c1d9b27fdc6d4cfca7fda63c4e3d263bf674ac9c28798c7e1ea861dcff3a3cc72c5d740a90a48abb334d77e2d3a2c22457d94ef090
|
data/LICENSE
ADDED
data/LICENSE-APACHE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright (C) 2026 Peter Gill <peter@majorsilence.com>
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
data/LICENSE-BSD
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
Copyright (C) 2026 Peter Gill <peter@majorsilence.com>
|
|
2
|
+
|
|
3
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
4
|
+
|
|
5
|
+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
6
|
+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
7
|
+
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
8
|
+
|
|
9
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/LICENSE-MIT
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (C) 2026 Peter Gill <peter@majorsilence.com>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the " Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice (including the next paragraph) shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
# Majorsilence Reporting — Ruby Wrappers
|
|
2
|
+
|
|
3
|
+
Three wrappers are provided for generating reports from Ruby. Pick the one that matches how you deploy the reporting engine:
|
|
4
|
+
|
|
5
|
+
| Wrapper | Mechanism | Requires |
|
|
6
|
+
|---|---|---|
|
|
7
|
+
| `Report` | subprocess → RdlCmd (.NET DLL) | .NET runtime on the host |
|
|
8
|
+
| `ReportAot` | subprocess → RdlCmd (self-contained or AOT binary) | nothing extra |
|
|
9
|
+
| `ReportNative` | in-process Fiddle FFI → rdlnative shared library | nothing extra |
|
|
10
|
+
|
|
11
|
+
**Ruby 3.0 or later** is recommended (`# frozen_string_literal: true` is used throughout; `Fiddle` is part of the standard library).
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
Install from [RubyGems](https://rubygems.org/gems/majorsilence_reporting):
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
gem install majorsilence_reporting
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Or add it to your `Gemfile`:
|
|
24
|
+
|
|
25
|
+
```ruby
|
|
26
|
+
gem 'majorsilence_reporting'
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
The gem itself has no runtime dependencies -- it uses the Ruby standard library only (`fiddle`, `fileutils`, `tempfile`). You still need one of the RdlCmd/rdlnative artifacts described below, matching the wrapper you choose.
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## Setup
|
|
34
|
+
|
|
35
|
+
### Install Ruby
|
|
36
|
+
|
|
37
|
+
- **Linux (Debian/Ubuntu):**
|
|
38
|
+
```bash
|
|
39
|
+
sudo apt-get update && sudo apt-get install -y ruby
|
|
40
|
+
ruby --version
|
|
41
|
+
```
|
|
42
|
+
- **macOS** (via Homebrew):
|
|
43
|
+
```bash
|
|
44
|
+
brew install ruby
|
|
45
|
+
ruby --version
|
|
46
|
+
```
|
|
47
|
+
- **Windows** — download the installer from [rubyinstaller.org](https://rubyinstaller.org/) or use winget:
|
|
48
|
+
```powershell
|
|
49
|
+
winget install RubyInstallerTeam.Ruby
|
|
50
|
+
ruby --version
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Install dependencies
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
bundle install
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
This installs `minitest` (needed only for running the test suite). The three wrappers themselves have no gem dependencies — they use the Ruby standard library only (`fiddle`, `fileutils`, `tempfile`).
|
|
60
|
+
|
|
61
|
+
### Use without Bundler
|
|
62
|
+
|
|
63
|
+
```ruby
|
|
64
|
+
$LOAD_PATH.unshift '/path/to/reporting-ruby/lib'
|
|
65
|
+
require 'majorsilence_reporting' # loads all three wrappers
|
|
66
|
+
# or load individually:
|
|
67
|
+
require 'majorsilence_reporting/report'
|
|
68
|
+
require 'majorsilence_reporting/report_aot'
|
|
69
|
+
require 'majorsilence_reporting/report_native'
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## Option 1 — `Report` (subprocess, .NET runtime required)
|
|
75
|
+
|
|
76
|
+
Use this when you have the .NET runtime installed on the host and want to run `RdlCmd.dll` through `dotnet`.
|
|
77
|
+
|
|
78
|
+
```ruby
|
|
79
|
+
require 'majorsilence_reporting/report'
|
|
80
|
+
|
|
81
|
+
rpt = Report.new(
|
|
82
|
+
'/path/to/report.rdl',
|
|
83
|
+
'/path/to/RdlCmd.dll',
|
|
84
|
+
'dotnet' # path_to_dotnet — omit when using a native exe on Windows
|
|
85
|
+
)
|
|
86
|
+
rpt.set_connection_string('Data Source=/path/to/northwindEF.db')
|
|
87
|
+
rpt.set_parameter('Country', 'Germany')
|
|
88
|
+
|
|
89
|
+
# Export to a file
|
|
90
|
+
rpt.export('pdf', '/tmp/output.pdf')
|
|
91
|
+
|
|
92
|
+
# Export to memory (binary String for pdf/tif/rtf; UTF-8 String for text formats)
|
|
93
|
+
data = rpt.export_to_memory('pdf')
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Windows
|
|
97
|
+
|
|
98
|
+
```ruby
|
|
99
|
+
rpt = Report.new(
|
|
100
|
+
'C:\reports\report.rdl',
|
|
101
|
+
'C:\RdlCmd\RdlCmd.exe'
|
|
102
|
+
)
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
## Option 2 — `ReportAot` (subprocess, no runtime required)
|
|
108
|
+
|
|
109
|
+
Use this with an AOT-compiled or self-contained RdlCmd binary. No `path_to_dotnet` argument — the binary runs directly.
|
|
110
|
+
|
|
111
|
+
Download the appropriate binary from the release:
|
|
112
|
+
- `majorsilence-reporting-rdlcmd-aot-linux.zip` → `linux-x64/` or `linux-arm64/`
|
|
113
|
+
- `majorsilence-reporting-rdlcmd-aot-osx.zip` → `osx-x64/` or `osx-arm64/`
|
|
114
|
+
- `majorsilence-reporting-rdlcmd-aot-windows.zip` → `win-x64/` or `win-arm64/`
|
|
115
|
+
|
|
116
|
+
Or use the self-contained (non-AOT) build from `majorsilence-reporting-rdlcmd-self-contained.zip`.
|
|
117
|
+
|
|
118
|
+
```ruby
|
|
119
|
+
require 'majorsilence_reporting/report_aot'
|
|
120
|
+
|
|
121
|
+
rpt = ReportAot.new(
|
|
122
|
+
'/path/to/report.rdl',
|
|
123
|
+
'/path/to/RdlCmd' # RdlCmd.exe on Windows
|
|
124
|
+
)
|
|
125
|
+
rpt.set_connection_string('Data Source=/path/to/northwindEF.db')
|
|
126
|
+
rpt.set_parameter('Country', 'Germany')
|
|
127
|
+
|
|
128
|
+
rpt.export('pdf', '/tmp/output.pdf')
|
|
129
|
+
data = rpt.export_to_memory('xlsx')
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
On Linux/macOS, make the binary executable:
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
chmod +x /path/to/RdlCmd
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
---
|
|
139
|
+
|
|
140
|
+
## Option 3 — `ReportNative` (in-process Fiddle FFI, no subprocess)
|
|
141
|
+
|
|
142
|
+
Use this for the lowest overhead: the reporting engine runs inside the Ruby process via `Fiddle`. No subprocess is spawned, no .NET runtime is required.
|
|
143
|
+
|
|
144
|
+
Download the native shared library from the release (`majorsilence-reporting-rdlnative-linux.zip`, `-osx.zip`, or `-windows.zip`) and extract it. The directory will contain the shared library and all its sibling libraries.
|
|
145
|
+
|
|
146
|
+
| Platform | Library filename |
|
|
147
|
+
|---|---|
|
|
148
|
+
| Linux | `librdlnative.so` |
|
|
149
|
+
| macOS | `librdlnative.dylib` |
|
|
150
|
+
| Windows | `rdlnative.dll` |
|
|
151
|
+
|
|
152
|
+
```ruby
|
|
153
|
+
require 'majorsilence_reporting/report_native'
|
|
154
|
+
|
|
155
|
+
# Load once per process — pass the full path to the shared library.
|
|
156
|
+
lib = RdlLibrary.load('/path/to/librdlnative.so')
|
|
157
|
+
|
|
158
|
+
rpt = ReportNative.new(lib, '/path/to/report.rdl')
|
|
159
|
+
rpt.set_connection_string('Data Source=/path/to/northwindEF.db')
|
|
160
|
+
rpt.set_parameter('Country', 'Germany')
|
|
161
|
+
|
|
162
|
+
# Export to a file
|
|
163
|
+
rpt.export('pdf', '/tmp/output.pdf')
|
|
164
|
+
|
|
165
|
+
# Export to memory — returns a binary String
|
|
166
|
+
data = rpt.export_to_memory('pdf')
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
On Linux, pre-load the library directory before starting Ruby:
|
|
170
|
+
|
|
171
|
+
```bash
|
|
172
|
+
export LD_LIBRARY_PATH=/path/to/rdlnative-dir:$LD_LIBRARY_PATH
|
|
173
|
+
ruby your_script.rb
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
---
|
|
177
|
+
|
|
178
|
+
## Supported export formats
|
|
179
|
+
|
|
180
|
+
| Format | Description | `Report` | `ReportAot` / `ReportNative` |
|
|
181
|
+
|---|---|---|---|
|
|
182
|
+
| `pdf` | PDF (default) | ✓ | ✓ |
|
|
183
|
+
| `csv` | Comma-separated values | ✓ | ✓ |
|
|
184
|
+
| `xlsx` | Excel workbook | ✓ | ✓ |
|
|
185
|
+
| `xlsx_table` | Excel workbook (table style) | | ✓ |
|
|
186
|
+
| `xml` | XML | ✓ | ✓ |
|
|
187
|
+
| `rtf` | Rich Text Format | ✓ | ✓ |
|
|
188
|
+
| `tif` | TIFF image | ✓ | ✓ |
|
|
189
|
+
| `tifb` | TIFF image (black & white) | | ✓ |
|
|
190
|
+
| `html` | HTML | ✓ | ✓ |
|
|
191
|
+
| `mht` | MHTML | | ✓ |
|
|
192
|
+
|
|
193
|
+
An unrecognised format string defaults to `pdf`.
|
|
194
|
+
|
|
195
|
+
---
|
|
196
|
+
|
|
197
|
+
## Running the tests
|
|
198
|
+
|
|
199
|
+
The test suite (`test/test_report_native.rb`) covers `ReportNative`. It uses Minitest and requires a published `rdlnative` shared library; tests are skipped automatically if `RDLNATIVE_LIB` is not set.
|
|
200
|
+
|
|
201
|
+
```bash
|
|
202
|
+
# Build the native library first (from the main Reporting repo)
|
|
203
|
+
dotnet publish RdlNative -c Release-DrawingCompat -r linux-x64 -f net10.0 \
|
|
204
|
+
--self-contained true -p:PublishAot=true \
|
|
205
|
+
-o /tmp/rdlnative-pub
|
|
206
|
+
|
|
207
|
+
# Run tests (set REPORTING_REPO_ROOT to the Reporting repo clone)
|
|
208
|
+
RDLNATIVE_LIB=/tmp/rdlnative-pub/librdlnative.so \
|
|
209
|
+
REPORTING_REPO_ROOT=/path/to/Reporting \
|
|
210
|
+
ruby test/test_report_native.rb
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
On macOS replace `linux-x64` with `osx-arm64` (or `osx-x64`) and `librdlnative.so` with `librdlnative.dylib`.
|
|
214
|
+
|
|
215
|
+
---
|
|
216
|
+
|
|
217
|
+
## Examples
|
|
218
|
+
|
|
219
|
+
See the `Examples/` subdirectory for runnable scripts:
|
|
220
|
+
|
|
221
|
+
- `test1.rb` — basic PDF export to file
|
|
222
|
+
- `test2-parameters.rb` — passing report parameters
|
|
223
|
+
- `test3-streaming.rb` — exporting to memory for streaming responses
|
|
224
|
+
- `test4-export-multiple-formats.rb` — exporting the same report to several formats
|
|
225
|
+
- `test5-set-data-from-code.rb` — supplying dataset rows from code instead of a database
|
|
226
|
+
|
|
227
|
+
---
|
|
228
|
+
|
|
229
|
+
## Releasing (maintainers)
|
|
230
|
+
|
|
231
|
+
Releases are published to [RubyGems](https://rubygems.org/gems/majorsilence_reporting) by `.github/workflows/publish.yml` using [Trusted Publishing](https://guides.rubygems.org/trusted-publishing/) (OIDC) -- no API key is stored in this repo.
|
|
232
|
+
|
|
233
|
+
One-time setup on rubygems.org, under Profile -> Trusted publishers (or "Pending trusted publishers" before the gem's first release):
|
|
234
|
+
|
|
235
|
+
| Field | Value |
|
|
236
|
+
|---|---|
|
|
237
|
+
| Gem name | `majorsilence_reporting` |
|
|
238
|
+
| Repository owner | `majorsilence` |
|
|
239
|
+
| Repository name | `reporting-ruby` |
|
|
240
|
+
| Workflow filename | `publish.yml` |
|
|
241
|
+
| Environment | `release` |
|
|
242
|
+
|
|
243
|
+
To cut a release:
|
|
244
|
+
|
|
245
|
+
```bash
|
|
246
|
+
# Bump the version
|
|
247
|
+
$EDITOR lib/majorsilence_reporting/version.rb
|
|
248
|
+
|
|
249
|
+
git commit -am "Release vX.Y.Z"
|
|
250
|
+
git tag vX.Y.Z
|
|
251
|
+
git push origin main --tags
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
Pushing the `vX.Y.Z` tag triggers the workflow, which runs the test suite and then uses [`rubygems/release-gem`](https://github.com/rubygems/release-gem) to build and push the gem.
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'fileutils'
|
|
4
|
+
require 'tempfile'
|
|
5
|
+
|
|
6
|
+
# Generates reports via the RdlCmd .NET command-line tool.
|
|
7
|
+
#
|
|
8
|
+
# Requires a .NET runtime on the host. For self-contained or AOT builds
|
|
9
|
+
# that need no runtime, use ReportAot instead.
|
|
10
|
+
#
|
|
11
|
+
# Usage:
|
|
12
|
+
# require 'majorsilence_reporting/report'
|
|
13
|
+
# # or: require 'majorsilence_reporting' (loads all three wrappers)
|
|
14
|
+
#
|
|
15
|
+
# rpt = Report.new('/path/to/report.rdl', '/path/to/RdlCmd.dll', 'dotnet')
|
|
16
|
+
# rpt.set_connection_string('Data Source=/path/to/db.sqlite')
|
|
17
|
+
# rpt.set_parameter('Country', 'Germany')
|
|
18
|
+
# rpt.export('pdf', '/tmp/output.pdf')
|
|
19
|
+
# data = rpt.export_to_memory('pdf')
|
|
20
|
+
#
|
|
21
|
+
# Supported export types: "pdf", "csv", "xlsx", "xml", "rtf", "tif", "html"
|
|
22
|
+
class Report
|
|
23
|
+
VALID_TYPES = %w[pdf csv xlsx xml rtf tif html].freeze
|
|
24
|
+
BINARY_TYPES = %w[pdf tif rtf].freeze
|
|
25
|
+
|
|
26
|
+
def initialize(report_path, rdl_cmd_path, path_to_dotnet = nil)
|
|
27
|
+
@report_path = report_path
|
|
28
|
+
@rdl_cmd_path = rdl_cmd_path
|
|
29
|
+
@path_to_dotnet = path_to_dotnet
|
|
30
|
+
@parameters = {}
|
|
31
|
+
@connection_string = nil
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# Set a report parameter value.
|
|
35
|
+
# name - parameter name as declared in the RDL
|
|
36
|
+
# value - parameter value (string)
|
|
37
|
+
def set_parameter(name, value)
|
|
38
|
+
@parameters[name] = value
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Override the connection string defined in the RDL.
|
|
42
|
+
def set_connection_string(connection_string)
|
|
43
|
+
@connection_string = connection_string
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# Render the report and save it to export_path.
|
|
47
|
+
# type - output format: "pdf", "csv", "xlsx", "xml", "rtf", "tif", "html". Defaults to "pdf".
|
|
48
|
+
# export_path - destination file path
|
|
49
|
+
def export(type, export_path)
|
|
50
|
+
type = 'pdf' unless VALID_TYPES.include?(type)
|
|
51
|
+
|
|
52
|
+
tmp = Tempfile.new('majorsilencereporting')
|
|
53
|
+
tmp_path = tmp.path
|
|
54
|
+
tmp_dir = File.dirname(tmp_path)
|
|
55
|
+
tmp.close
|
|
56
|
+
FileUtils.cp(@report_path, tmp_path)
|
|
57
|
+
|
|
58
|
+
rdl_arg = "/f#{tmp_path}"
|
|
59
|
+
@parameters.each_with_index do |(key, value), i|
|
|
60
|
+
rdl_arg += (i.zero? ? '?' : '&') + "#{key}=#{value}"
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
cmd = []
|
|
64
|
+
cmd << @path_to_dotnet if @path_to_dotnet
|
|
65
|
+
cmd += [@rdl_cmd_path, rdl_arg, "/t#{type}", "/o#{tmp_dir}"]
|
|
66
|
+
cmd << "/c#{@connection_string}" if @connection_string
|
|
67
|
+
|
|
68
|
+
system(*cmd) or raise "RdlCmd failed (exit #{$?.exitstatus})"
|
|
69
|
+
|
|
70
|
+
tmp_out = File.join(tmp_dir, File.basename(tmp_path) + ".#{type}")
|
|
71
|
+
FileUtils.cp(tmp_out, export_path)
|
|
72
|
+
File.delete(tmp_path)
|
|
73
|
+
File.delete(tmp_out)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# Render the report and return the output.
|
|
77
|
+
# Returns binary String for pdf/tif/rtf; UTF-8 String for text formats.
|
|
78
|
+
# type - output format (defaults to "pdf" if unrecognised)
|
|
79
|
+
def export_to_memory(type)
|
|
80
|
+
type = 'pdf' unless VALID_TYPES.include?(type)
|
|
81
|
+
|
|
82
|
+
tmp = Tempfile.new('majorsilencereporting')
|
|
83
|
+
tmp_path = tmp.path
|
|
84
|
+
tmp.close
|
|
85
|
+
tmp.unlink
|
|
86
|
+
|
|
87
|
+
export(type, tmp_path)
|
|
88
|
+
|
|
89
|
+
data = BINARY_TYPES.include?(type) ? File.binread(tmp_path) : File.read(tmp_path, encoding: 'UTF-8')
|
|
90
|
+
File.delete(tmp_path) if File.exist?(tmp_path)
|
|
91
|
+
data
|
|
92
|
+
end
|
|
93
|
+
end
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'fileutils'
|
|
4
|
+
require 'tempfile'
|
|
5
|
+
|
|
6
|
+
# Report class for use with the AOT or self-contained RdlCmd binary.
|
|
7
|
+
#
|
|
8
|
+
# Unlike Report, this class does not accept a path_to_dotnet argument.
|
|
9
|
+
# rdl_cmd_path must point to the native AOT or self-contained executable
|
|
10
|
+
# (e.g. RdlCmd on Linux/macOS, RdlCmd.exe on Windows) — no .NET runtime is required.
|
|
11
|
+
#
|
|
12
|
+
# Usage:
|
|
13
|
+
# require 'majorsilence_reporting/report_aot'
|
|
14
|
+
#
|
|
15
|
+
# rpt = ReportAot.new('/path/to/report.rdl', '/path/to/RdlCmd')
|
|
16
|
+
# rpt.set_parameter('Country', 'Germany')
|
|
17
|
+
# rpt.set_connection_string('Data Source=myserver.db')
|
|
18
|
+
# rpt.export('pdf', '/tmp/output.pdf')
|
|
19
|
+
#
|
|
20
|
+
# Supported export types: "pdf", "csv", "xlsx", "xlsx_table", "xml", "rtf", "tif", "tifb", "html", "mht".
|
|
21
|
+
class ReportAot
|
|
22
|
+
VALID_TYPES = %w[pdf csv xlsx xlsx_table xml rtf tif tifb html mht].freeze
|
|
23
|
+
BINARY_TYPES = %w[pdf tif tifb rtf xlsx xlsx_table].freeze
|
|
24
|
+
|
|
25
|
+
def initialize(report_path, rdl_cmd_path)
|
|
26
|
+
@report_path = report_path
|
|
27
|
+
@rdl_cmd_path = rdl_cmd_path
|
|
28
|
+
@parameters = {}
|
|
29
|
+
@connection_string = nil
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# Set a report parameter value.
|
|
33
|
+
# name - parameter name as declared in the RDL
|
|
34
|
+
# value - parameter value (string)
|
|
35
|
+
def set_parameter(name, value)
|
|
36
|
+
@parameters[name] = value
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Override the connection string defined in the RDL.
|
|
40
|
+
def set_connection_string(connection_string)
|
|
41
|
+
@connection_string = connection_string
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Render the report and save it to export_path.
|
|
45
|
+
# type - output format: "pdf", "csv", "xlsx", "xlsx_table", "xml",
|
|
46
|
+
# "rtf", "tif", "tifb", "html", "mht". Defaults to "pdf".
|
|
47
|
+
# export_path - destination file path
|
|
48
|
+
def export(type, export_path)
|
|
49
|
+
type = 'pdf' unless VALID_TYPES.include?(type)
|
|
50
|
+
|
|
51
|
+
tmp = Tempfile.new('majorsilencereporting')
|
|
52
|
+
tmp_path = tmp.path
|
|
53
|
+
tmp_dir = File.dirname(tmp_path)
|
|
54
|
+
tmp.close
|
|
55
|
+
FileUtils.cp(@report_path, tmp_path)
|
|
56
|
+
|
|
57
|
+
rdl_arg = "/f#{tmp_path}"
|
|
58
|
+
@parameters.each_with_index do |(key, value), i|
|
|
59
|
+
rdl_arg += (i.zero? ? '?' : '&') + "#{key}=#{value}"
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
cmd = [@rdl_cmd_path, rdl_arg, "/t#{type}", "/o#{tmp_dir}"]
|
|
63
|
+
cmd << "/c#{@connection_string}" if @connection_string
|
|
64
|
+
|
|
65
|
+
system(*cmd) or raise "RdlCmd failed (exit #{$?.exitstatus})"
|
|
66
|
+
|
|
67
|
+
tmp_out = File.join(tmp_dir, File.basename(tmp_path) + ".#{type}")
|
|
68
|
+
FileUtils.cp(tmp_out, export_path)
|
|
69
|
+
File.delete(tmp_path)
|
|
70
|
+
File.delete(tmp_out)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# Render the report and return the output.
|
|
74
|
+
# Returns binary String for pdf/tif/tifb/rtf/xlsx; UTF-8 String for text formats.
|
|
75
|
+
# type - output format (defaults to "pdf" if unrecognised)
|
|
76
|
+
def export_to_memory(type)
|
|
77
|
+
type = 'pdf' unless VALID_TYPES.include?(type)
|
|
78
|
+
|
|
79
|
+
tmp = Tempfile.new('majorsilencereporting')
|
|
80
|
+
tmp_path = tmp.path
|
|
81
|
+
tmp.close
|
|
82
|
+
tmp.unlink
|
|
83
|
+
|
|
84
|
+
export(type, tmp_path)
|
|
85
|
+
|
|
86
|
+
data = BINARY_TYPES.include?(type) ? File.binread(tmp_path) : File.read(tmp_path, encoding: 'UTF-8')
|
|
87
|
+
File.delete(tmp_path) if File.exist?(tmp_path)
|
|
88
|
+
data
|
|
89
|
+
end
|
|
90
|
+
end
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'fiddle'
|
|
4
|
+
require 'fiddle/import'
|
|
5
|
+
require 'tempfile'
|
|
6
|
+
|
|
7
|
+
# Ruby Fiddle wrapper for the rdlnative shared library.
|
|
8
|
+
#
|
|
9
|
+
# Loads the Majorsilence Reporting engine in-process via Fiddle — no subprocess
|
|
10
|
+
# is spawned, no .NET runtime is required on the host.
|
|
11
|
+
#
|
|
12
|
+
# Platform-specific library filenames:
|
|
13
|
+
# Linux: librdlnative.so
|
|
14
|
+
# macOS: librdlnative.dylib
|
|
15
|
+
# Windows: rdlnative.dll
|
|
16
|
+
#
|
|
17
|
+
# Usage:
|
|
18
|
+
# require 'majorsilence_reporting/report_native'
|
|
19
|
+
#
|
|
20
|
+
# lib = RdlLibrary.load('/path/to/librdlnative.so')
|
|
21
|
+
#
|
|
22
|
+
# rpt = ReportNative.new(lib, '/path/to/report.rdl')
|
|
23
|
+
# rpt.set_parameter('Country', 'Germany')
|
|
24
|
+
# rpt.set_connection_string('Data Source=myserver.db')
|
|
25
|
+
#
|
|
26
|
+
# # Export to a file
|
|
27
|
+
# rpt.export('pdf', '/tmp/output.pdf')
|
|
28
|
+
#
|
|
29
|
+
# # Export to bytes
|
|
30
|
+
# data = rpt.export_to_memory('pdf')
|
|
31
|
+
#
|
|
32
|
+
# Supported export types: "pdf", "csv", "xlsx", "xlsx_table", "xml", "rtf",
|
|
33
|
+
# "tif", "tifb", "html", "mht"
|
|
34
|
+
|
|
35
|
+
module RdlLibrary
|
|
36
|
+
extend Fiddle::Importer
|
|
37
|
+
|
|
38
|
+
# Load the rdlnative shared library and initialize the engine.
|
|
39
|
+
# Returns a Hash of bound Fiddle::Function objects.
|
|
40
|
+
# Call this once per process before creating any ReportNative instances.
|
|
41
|
+
def self.load(lib_path)
|
|
42
|
+
lib_path = File.expand_path(lib_path)
|
|
43
|
+
lib_dir = File.dirname(lib_path)
|
|
44
|
+
|
|
45
|
+
# Tell the C# resolver where to find P/Invoke sibling libraries (libSkiaSharp.so,
|
|
46
|
+
# libe_sqlite3.so, etc.) — must be set before rdl_init() is called.
|
|
47
|
+
ENV['RDLNATIVE_LIB_DIR'] = lib_dir
|
|
48
|
+
|
|
49
|
+
# Pre-load all shared libraries in the directory with RTLD_GLOBAL (Fiddle's
|
|
50
|
+
# default). On .NET 10+, libSystem.Native.so and sibling P/Invoke targets are
|
|
51
|
+
# shared libraries — they must be globally visible before rdlnative.so runs.
|
|
52
|
+
ext = RUBY_PLATFORM =~ /darwin/ ? '*.dylib' : '*.so'
|
|
53
|
+
Dir.glob(File.join(lib_dir, ext)).sort.each do |f|
|
|
54
|
+
begin Fiddle.dlopen(f) rescue Fiddle::DLError; end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
handle = Fiddle.dlopen(lib_path)
|
|
58
|
+
|
|
59
|
+
fns = {
|
|
60
|
+
rdl_init: Fiddle::Function.new(
|
|
61
|
+
handle['rdl_init'], [], Fiddle::TYPE_INT
|
|
62
|
+
),
|
|
63
|
+
rdl_report_open: Fiddle::Function.new(
|
|
64
|
+
handle['rdl_report_open'],
|
|
65
|
+
[Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP],
|
|
66
|
+
Fiddle::TYPE_VOIDP
|
|
67
|
+
),
|
|
68
|
+
rdl_report_set_param: Fiddle::Function.new(
|
|
69
|
+
handle['rdl_report_set_param'],
|
|
70
|
+
[Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP],
|
|
71
|
+
Fiddle::TYPE_INT
|
|
72
|
+
),
|
|
73
|
+
rdl_dataset_set_field: Fiddle::Function.new(
|
|
74
|
+
handle['rdl_dataset_set_field'],
|
|
75
|
+
[Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP],
|
|
76
|
+
Fiddle::TYPE_INT
|
|
77
|
+
),
|
|
78
|
+
rdl_dataset_commit_row: Fiddle::Function.new(
|
|
79
|
+
handle['rdl_dataset_commit_row'],
|
|
80
|
+
[Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP],
|
|
81
|
+
Fiddle::TYPE_INT
|
|
82
|
+
),
|
|
83
|
+
rdl_report_render_file: Fiddle::Function.new(
|
|
84
|
+
handle['rdl_report_render_file'],
|
|
85
|
+
[Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP],
|
|
86
|
+
Fiddle::TYPE_INT
|
|
87
|
+
),
|
|
88
|
+
rdl_free: Fiddle::Function.new(
|
|
89
|
+
handle['rdl_free'], [Fiddle::TYPE_VOIDP], Fiddle::TYPE_VOID
|
|
90
|
+
),
|
|
91
|
+
rdl_report_close: Fiddle::Function.new(
|
|
92
|
+
handle['rdl_report_close'], [Fiddle::TYPE_VOIDP], Fiddle::TYPE_VOID
|
|
93
|
+
),
|
|
94
|
+
rdl_last_error: Fiddle::Function.new(
|
|
95
|
+
handle['rdl_last_error'], [], Fiddle::TYPE_VOIDP
|
|
96
|
+
),
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
ret = fns[:rdl_init].call
|
|
100
|
+
raise "rdl_init failed: #{rdl_last_error_str(fns)}" unless ret.zero?
|
|
101
|
+
|
|
102
|
+
fns
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def self.rdl_last_error_str(fns)
|
|
106
|
+
ptr = fns[:rdl_last_error].call
|
|
107
|
+
return 'unknown error' if ptr.nil? || ptr.zero?
|
|
108
|
+
|
|
109
|
+
Fiddle::Pointer.new(ptr).to_s
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
class ReportNative
|
|
114
|
+
VALID_TYPES = %w[pdf csv xlsx xlsx_table xml rtf tif tifb html mht].freeze
|
|
115
|
+
|
|
116
|
+
def initialize(fns, report_path)
|
|
117
|
+
@fns = fns
|
|
118
|
+
@report_path = report_path
|
|
119
|
+
@connection_string = nil
|
|
120
|
+
@parameters = {}
|
|
121
|
+
@data_sets = {}
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
# Set a report parameter value.
|
|
125
|
+
# name - parameter name as declared in the RDL
|
|
126
|
+
# value - parameter value (string)
|
|
127
|
+
def set_parameter(name, value)
|
|
128
|
+
@parameters[name] = value
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
# Override the connection string defined in the RDL.
|
|
132
|
+
def set_connection_string(connection_string)
|
|
133
|
+
@connection_string = connection_string
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
# Supply in-memory data for a named dataset, bypassing any database query.
|
|
137
|
+
# dataset_name - name of the DataSet element in the RDL (e.g. "Data")
|
|
138
|
+
# rows - Array of Hashes mapping field name => value (all values as strings).
|
|
139
|
+
# Field names must match the <Field Name="..."> values in the RDL.
|
|
140
|
+
#
|
|
141
|
+
# SkipDatabaseSchemaValidation is set automatically when dataset rows are present,
|
|
142
|
+
# so no DB connection is needed at parse or render time.
|
|
143
|
+
#
|
|
144
|
+
# Example:
|
|
145
|
+
# rpt.add_data('Data', [
|
|
146
|
+
# { 'Product' => 'Chai', 'Amount' => '1250.00' },
|
|
147
|
+
# { 'Product' => 'Chang', 'Amount' => '980.50' },
|
|
148
|
+
# ])
|
|
149
|
+
def add_data(dataset_name, rows)
|
|
150
|
+
@data_sets[dataset_name] = rows
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
# Render the report and save it to export_path.
|
|
154
|
+
# type - output format (defaults to "pdf")
|
|
155
|
+
# export_path - destination file path
|
|
156
|
+
def export(type, export_path)
|
|
157
|
+
fmt = VALID_TYPES.include?(type) ? type : 'pdf'
|
|
158
|
+
with_handle do |h|
|
|
159
|
+
ret = @fns[:rdl_report_render_file].call(h, c_str(export_path), c_str(fmt))
|
|
160
|
+
raise_last_error('rdl_report_render_file') unless ret.zero?
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
# Render the report and return the output.
|
|
165
|
+
# Returns a binary String for all formats.
|
|
166
|
+
# type - output format (defaults to "pdf")
|
|
167
|
+
def export_to_memory(type)
|
|
168
|
+
fmt = VALID_TYPES.include?(type) ? type : 'pdf'
|
|
169
|
+
tmp = Tempfile.new(['rdlnative', ".#{fmt}"], binmode: true)
|
|
170
|
+
tmp_path = tmp.path
|
|
171
|
+
tmp.close
|
|
172
|
+
begin
|
|
173
|
+
export(fmt, tmp_path)
|
|
174
|
+
File.binread(tmp_path)
|
|
175
|
+
ensure
|
|
176
|
+
File.delete(tmp_path) if File.exist?(tmp_path)
|
|
177
|
+
end
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
private
|
|
181
|
+
|
|
182
|
+
# Open a native handle, yield it with params and dataset rows applied, then close it.
|
|
183
|
+
def with_handle
|
|
184
|
+
cs_ptr = @connection_string ? c_str(@connection_string) : Fiddle::NULL
|
|
185
|
+
h = @fns[:rdl_report_open].call(c_str(@report_path), cs_ptr)
|
|
186
|
+
raise_last_error('rdl_report_open') if h.nil? || h.zero?
|
|
187
|
+
begin
|
|
188
|
+
@parameters.each do |name, value|
|
|
189
|
+
ret = @fns[:rdl_report_set_param].call(h, c_str(name), c_str(value))
|
|
190
|
+
raise_last_error('rdl_report_set_param') unless ret.zero?
|
|
191
|
+
end
|
|
192
|
+
@data_sets.each do |ds_name, rows|
|
|
193
|
+
ds_ptr = c_str(ds_name)
|
|
194
|
+
rows.each do |row|
|
|
195
|
+
row.each do |field, value|
|
|
196
|
+
ret = @fns[:rdl_dataset_set_field].call(h, ds_ptr, c_str(field.to_s), c_str(value.to_s))
|
|
197
|
+
raise_last_error('rdl_dataset_set_field') unless ret.zero?
|
|
198
|
+
end
|
|
199
|
+
ret = @fns[:rdl_dataset_commit_row].call(h, ds_ptr)
|
|
200
|
+
raise_last_error('rdl_dataset_commit_row') unless ret.zero?
|
|
201
|
+
end
|
|
202
|
+
end
|
|
203
|
+
yield h
|
|
204
|
+
ensure
|
|
205
|
+
@fns[:rdl_report_close].call(h)
|
|
206
|
+
end
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
def c_str(str)
|
|
210
|
+
Fiddle::Pointer[str.encode('UTF-8') + "\0"]
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
def raise_last_error(fn)
|
|
214
|
+
ptr = @fns[:rdl_last_error].call
|
|
215
|
+
msg = (ptr && !ptr.zero?) ? Fiddle::Pointer.new(ptr).to_s : 'unknown error'
|
|
216
|
+
raise "#{fn} failed: #{msg}"
|
|
217
|
+
end
|
|
218
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: majorsilence_reporting
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 26.0.2
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Peter Gill
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: fiddle
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - "~>"
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '1.1'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - "~>"
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '1.1'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: minitest
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - "~>"
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '5.0'
|
|
33
|
+
type: :development
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - "~>"
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '5.0'
|
|
40
|
+
- !ruby/object:Gem::Dependency
|
|
41
|
+
name: rake
|
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - "~>"
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '13.0'
|
|
47
|
+
type: :development
|
|
48
|
+
prerelease: false
|
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - "~>"
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '13.0'
|
|
54
|
+
description: Ruby wrappers for Majorsilence Reporting -- render RDL reports to PDF,
|
|
55
|
+
Excel, CSV, HTML and more via an in-process native library (Fiddle FFI) or a subprocess-based
|
|
56
|
+
.NET runner.
|
|
57
|
+
email:
|
|
58
|
+
- peter@majorsilence.com
|
|
59
|
+
executables: []
|
|
60
|
+
extensions: []
|
|
61
|
+
extra_rdoc_files: []
|
|
62
|
+
files:
|
|
63
|
+
- LICENSE
|
|
64
|
+
- LICENSE-APACHE
|
|
65
|
+
- LICENSE-BSD
|
|
66
|
+
- LICENSE-MIT
|
|
67
|
+
- README.md
|
|
68
|
+
- lib/majorsilence_reporting.rb
|
|
69
|
+
- lib/majorsilence_reporting/report.rb
|
|
70
|
+
- lib/majorsilence_reporting/report_aot.rb
|
|
71
|
+
- lib/majorsilence_reporting/report_native.rb
|
|
72
|
+
- lib/majorsilence_reporting/version.rb
|
|
73
|
+
homepage: https://github.com/majorsilence/Reporting
|
|
74
|
+
licenses:
|
|
75
|
+
- MIT
|
|
76
|
+
- Apache-2.0
|
|
77
|
+
- BSD-2-Clause
|
|
78
|
+
metadata:
|
|
79
|
+
homepage_uri: https://github.com/majorsilence/Reporting
|
|
80
|
+
source_code_uri: https://github.com/majorsilence/reporting-ruby
|
|
81
|
+
changelog_uri: https://github.com/majorsilence/reporting-ruby/releases
|
|
82
|
+
bug_tracker_uri: https://github.com/majorsilence/reporting-ruby/issues
|
|
83
|
+
rubygems_mfa_required: 'true'
|
|
84
|
+
rdoc_options: []
|
|
85
|
+
require_paths:
|
|
86
|
+
- lib
|
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
88
|
+
requirements:
|
|
89
|
+
- - ">="
|
|
90
|
+
- !ruby/object:Gem::Version
|
|
91
|
+
version: '3.0'
|
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - ">="
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '0'
|
|
97
|
+
requirements: []
|
|
98
|
+
rubygems_version: 4.0.10
|
|
99
|
+
specification_version: 4
|
|
100
|
+
summary: Ruby bindings for Majorsilence Reporting
|
|
101
|
+
test_files: []
|