gem_hadar 1.24.0 → 1.26.0
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 +4 -4
- data/README.md +225 -10
- data/Rakefile +1 -0
- data/VERSION +1 -1
- data/gem_hadar.gemspec +6 -5
- data/lib/gem_hadar/prompt_template.rb +91 -0
- data/lib/gem_hadar/setup.rb +4 -0
- data/lib/gem_hadar/template_compiler.rb +29 -0
- data/lib/gem_hadar/utils.rb +41 -0
- data/lib/gem_hadar/version.rb +1 -1
- data/lib/gem_hadar.rb +494 -104
- metadata +21 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f3fefed7b5fd9123e2944de9cf2defcd9f1794aaa7d0058621539b22a2e076d3
|
4
|
+
data.tar.gz: 8734f8f3cf30c0a0b501e5484a58bc5b4bbc4190258133f6de7b1105f17c7383
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 867a63019ba90544ba9b0c91478482128d3527221d9c11473929d9f18b5c74673d2fc3ab5844bc26779680b724965a9a7a455518286c5ca9a496342371c31c1a
|
7
|
+
data.tar.gz: a6fa278536336a668d025947b3d9f274d4cc02ae9e2a3d50bb2a2a87b42ee2d351bfb191d9eb472bd215b521c34b561c4ee5d9f15cfcec93576f98871df23c10
|
data/README.md
CHANGED
@@ -2,7 +2,76 @@
|
|
2
2
|
|
3
3
|
## Description
|
4
4
|
|
5
|
-
Ruby library that provides support for building gems
|
5
|
+
The `gem_hadar` gem is a Ruby library that provides support for building gems
|
6
|
+
using rake tasks. It is a comprehensive Ruby gem automation tool that provides:
|
7
|
+
|
8
|
+
- **Automated gem building and packaging** - Complete build workflows with
|
9
|
+
🛠️Rake task orchestration
|
10
|
+
- **Git workflow automation** - Version management, tagging, remote operations,
|
11
|
+
and repository setup with 🔄git integration
|
12
|
+
- **GitHub release management** - Automated release creation with 🤖AI-powered
|
13
|
+
changelog generation using Ollama
|
14
|
+
- **Testing framework integration** - Built-in support for RSpec, Test::Unit,
|
15
|
+
and RCov code coverage testing with 🧪testing tools
|
16
|
+
- **Documentation generation** - YARD integration with private/public
|
17
|
+
documentation tasks and coverage reporting with 📚documentation
|
18
|
+
- **RVM configuration management** - Automatic .rvmrc file generation for
|
19
|
+
consistent development environments with 🎯RVM setup
|
20
|
+
- **CI/CD pipeline capabilities** - Complete workflows from build to publish
|
21
|
+
with dependency management using ⚙️CI/CD automation
|
22
|
+
- **Semantic versioning automation** - 👾AI-powered version bump suggestions
|
23
|
+
based on code changes
|
24
|
+
- **Extension compilation support** - Automatic compilation of C extensions
|
25
|
+
when needed with 🏗️extension building
|
26
|
+
- **DSL-based configuration** - Simple block syntax in Rakefile for easy
|
27
|
+
workflow setup with 📝configuration
|
28
|
+
- **Gemfile and .gitignore automation** - Automatic creation and management of
|
29
|
+
essential project files with 📦dependency management
|
30
|
+
|
31
|
+
## Workflow Diagrams
|
32
|
+
|
33
|
+
### Gem Build Process
|
34
|
+
```mermaid
|
35
|
+
graph LR
|
36
|
+
A[Source Code] --> B[Gemfile Setup]
|
37
|
+
B --> C[Bundle Install]
|
38
|
+
C --> D[Run Tests]
|
39
|
+
D --> E[Generate Documentation]
|
40
|
+
E --> F[Build Gem]
|
41
|
+
F --> G[Version Bump]
|
42
|
+
G --> H[Push to GitHub]
|
43
|
+
G --> I[Push to Rubygems]
|
44
|
+
I --> J[AI Changelog]
|
45
|
+
H --> J[AI Changelog]
|
46
|
+
J --> K[Create Release]
|
47
|
+
```
|
48
|
+
|
49
|
+
### AI Versioning Flow
|
50
|
+
|
51
|
+
```mermaid
|
52
|
+
graph LR
|
53
|
+
A[Code Changes] --> B[Semantic Analysis]
|
54
|
+
B --> C[AI Suggestion]
|
55
|
+
C --> D[Version Decision]
|
56
|
+
D --> E[Changelog Generation]
|
57
|
+
E --> F[Release Creation]
|
58
|
+
```
|
59
|
+
|
60
|
+
### Testing Suite Overview
|
61
|
+
|
62
|
+
```mermaid
|
63
|
+
graph TD
|
64
|
+
A[Test Run] --> B[RSpec Tests]
|
65
|
+
A[Test Run] --> C[Test::Unit Tests]
|
66
|
+
B --> D[Code Coverage]
|
67
|
+
C --> D[Code Coverage]
|
68
|
+
D --> E[Failures?]
|
69
|
+
E -->|Yes| F[Fix Code]
|
70
|
+
E -->|No| G[Proceed]
|
71
|
+
F --> H[Re-run Tests]
|
72
|
+
H --> I[Success]
|
73
|
+
I --> J[Build Gem]
|
74
|
+
```
|
6
75
|
|
7
76
|
## Download
|
8
77
|
|
@@ -12,37 +81,183 @@ The source of this library is located at
|
|
12
81
|
|
13
82
|
or can be installed via
|
14
83
|
|
15
|
-
```
|
84
|
+
```bash
|
16
85
|
$ gem install gem_hadar
|
17
86
|
```
|
18
87
|
|
19
88
|
## Usage
|
20
89
|
|
21
|
-
|
90
|
+
### Pre-requisites
|
22
91
|
|
23
|
-
|
92
|
+
Before using `gem_hadar`, ensure you have initialized a Git repository in your
|
93
|
+
project directory. Many of the gem's commands assume Git is available and
|
94
|
+
properly configured in the current working directory.
|
95
|
+
|
96
|
+
### Quick Start with Generator
|
97
|
+
|
98
|
+
Create a new directory and execute:
|
99
|
+
|
100
|
+
```bash
|
24
101
|
$ gem_hadar
|
25
102
|
```
|
26
103
|
|
27
|
-
Edit the
|
104
|
+
This generates a basic gem structure with a Rakefile. Edit the generated Rakefile until:
|
28
105
|
|
29
|
-
```
|
106
|
+
```bash
|
30
107
|
$ rake gemspec
|
31
108
|
```
|
32
109
|
|
33
110
|
and then
|
34
111
|
|
112
|
+
```bash
|
113
|
+
$ rake build
|
114
|
+
```
|
115
|
+
|
116
|
+
are performed as desired.
|
117
|
+
|
118
|
+
### YARD Documentation
|
119
|
+
|
120
|
+
`gem_hadar` supports generating YARD documentation. To generate documentation, run:
|
121
|
+
|
122
|
+
```bash
|
123
|
+
$ rake doc
|
35
124
|
```
|
125
|
+
|
126
|
+
This will create documentation in the `doc` directory using YARD.
|
127
|
+
|
128
|
+
### Rakefile Configuration Example
|
129
|
+
|
130
|
+
For more advanced control, here's a complete Rakefile configuration example:
|
131
|
+
|
132
|
+
```ruby
|
133
|
+
# Rakefile
|
134
|
+
require 'gem_hadar'
|
135
|
+
|
136
|
+
GemHadar do
|
137
|
+
# Set developing to true if you don't have a homepage set yet
|
138
|
+
#developing true
|
139
|
+
|
140
|
+
name 'mygemname'
|
141
|
+
path_name 'mygem'
|
142
|
+
path_module 'Mygem'
|
143
|
+
author 'My name'
|
144
|
+
email 'my@mail'
|
145
|
+
homepage "https://github.com/younameit/mygem"
|
146
|
+
summary 'Precious gem'
|
147
|
+
description 'Precious detailed gem'
|
148
|
+
test_dir 'spec'
|
149
|
+
ignore 'pkg', 'Gemfile.lock', '.DS_Store'
|
150
|
+
|
151
|
+
readme 'README.md'
|
152
|
+
title "#{name.camelize} -- My library"
|
153
|
+
licenses << 'Apache-2.0'
|
154
|
+
|
155
|
+
dependency 'sinatra', '~> 3.2'
|
156
|
+
development_dependency 'rake'
|
157
|
+
development_dependency 'rspec'
|
158
|
+
end
|
159
|
+
```
|
160
|
+
|
161
|
+
Note that `gem_hadar` is ["self hosted"](Rakefile)
|
162
|
+
|
163
|
+
### Available Tasks
|
164
|
+
|
165
|
+
You can list all available tasks with:
|
166
|
+
|
167
|
+
```bash
|
168
|
+
$ rake -T
|
169
|
+
```
|
170
|
+
|
171
|
+
#### Core Tasks
|
172
|
+
|
173
|
+
- `rake build` - Build task (builds all packages for a release)
|
174
|
+
- `rake release` - Release the new version 1.2.3 for the gem foo
|
175
|
+
|
176
|
+
#### Build Tasks
|
177
|
+
|
178
|
+
- `rake gemspec` - Create a gemspec file
|
179
|
+
- `rake package` - Build all the packages
|
180
|
+
- `rake gem` - Build the gem file foo-1.2.3.gem
|
181
|
+
- `rake clobber` - Remove any generated files
|
182
|
+
- `rake clobber_package` - Remove package products
|
183
|
+
- `rake repackage` - Force a rebuild of the package files
|
184
|
+
|
185
|
+
#### Version Management
|
186
|
+
|
187
|
+
- `rake version` - Writing version information for foo
|
188
|
+
- `rake version:show` - Displaying the current version
|
189
|
+
- `rake version:list` - List all versions in order
|
190
|
+
- `rake version:diff` - Displaying the diff from env var VERSION to the next version or HEAD
|
191
|
+
- `rake version:tag` - Tag this commit as version 1.2.3
|
192
|
+
- `rake version:bump` - Bump version with AI suggestion
|
193
|
+
- `rake version:bump:major` - Bump major version
|
194
|
+
- `rake version:bump:minor` - Bump minor version
|
195
|
+
- `rake version:bump:build` - Bump build version
|
196
|
+
- `rake version:push` - Push version 1.2.3 to all git remotes: origin
|
197
|
+
- `rake version:origin:push` - Push version 1.2.3 to git remote origin
|
198
|
+
|
199
|
+
#### Documentation
|
200
|
+
|
201
|
+
- `rake doc` - Create yard documentation (including private)
|
202
|
+
- `rake yard_doc` - Generate YARD Documentation
|
203
|
+
- `rake yard:doc` - Create yard documentation
|
204
|
+
- `rake yard:private` - Create yard documentation (including private)
|
205
|
+
- `rake yard:public` - Create yard documentation
|
206
|
+
- `rake yard:clean` - Clean the yard documentation
|
207
|
+
- `rake yard:view` - View the yard documentation
|
208
|
+
- `rake yard:list-undoc` - List all undocumented classes/modules/methods
|
209
|
+
|
210
|
+
#### Testing & Development
|
211
|
+
|
212
|
+
- `rake run_specs` - Run RSpec code examples
|
213
|
+
- `rake clean` - Remove any temporary products
|
214
|
+
- `rake gems:install` - Install all gems from the Gemfile
|
215
|
+
- `rake gem_hadar:update` - Update `gem_hadar` to a different version
|
216
|
+
- `rake rvm` - Create .rvmrc file
|
217
|
+
- `rake default` - Default task
|
218
|
+
- `rake compile` - Compile project extensions (if configured)
|
219
|
+
|
220
|
+
#### Publishing Tasks
|
221
|
+
- `rake push` - Push all changes for version 1.2.3 into the internets
|
222
|
+
- `rake github:release` - Create a new GitHub release for the current version
|
223
|
+
with AI-generated changelog
|
224
|
+
|
225
|
+
### Update Version
|
226
|
+
|
227
|
+
Use one of the following rake tasks to bump the version:
|
228
|
+
|
229
|
+
- `rake version:bump:major` - Bump major version (e.g., 1.2.3 → 2.0.0)
|
230
|
+
- `rake version:bump:minor` - Bump minor version (e.g., 1.2.3 → 1.3.0)
|
231
|
+
- `rake version:bump:build` - Bump build version (e.g., 1.2.3 → 1.2.4)
|
232
|
+
- `rake version:bump` - Get AI-powered suggestion for appropriate bump level
|
233
|
+
|
234
|
+
Or bump your [VERSION](./VERSION) file by hand.
|
235
|
+
|
236
|
+
### Release
|
237
|
+
|
238
|
+
```bash
|
36
239
|
$ rake build
|
37
240
|
```
|
38
241
|
|
39
|
-
|
242
|
+
This command will execute a series of dependent tasks in order: cleaning
|
243
|
+
previous builds, generating the gem specification, packaging the gem, and
|
244
|
+
creating a git tag with the current version in git.
|
245
|
+
|
246
|
+
After all the files have been changed correctly and the git tags have been
|
247
|
+
moved forward to the appropriate commit you can finally enter:
|
248
|
+
|
249
|
+
```bash
|
250
|
+
$ rake release
|
251
|
+
```
|
252
|
+
|
253
|
+
The `rake release` command performs the final publishing steps: pushing the
|
254
|
+
master branch and version tag to all git remotes, pushing the gem package to
|
255
|
+
RubyGems.org, and creating a GitHub release with AI-generated changelog.
|
40
256
|
|
41
257
|
## Author
|
42
258
|
|
43
|
-
Florian Frank
|
44
|
-
**GemHadar** was written by [Florian Frank](mailto:flori@ping.de)
|
259
|
+
**GemHadar** was written by [Florian Frank](mailto:flori@ping.de).
|
45
260
|
|
46
261
|
## License
|
47
262
|
|
48
|
-
This software is licensed under the
|
263
|
+
This software is licensed under the [MIT](./LICENSE) license.
|
data/Rakefile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.26.0
|
data/gem_hadar.gemspec
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: gem_hadar 1.
|
2
|
+
# stub: gem_hadar 1.26.0 ruby lib
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "gem_hadar".freeze
|
6
|
-
s.version = "1.
|
6
|
+
s.version = "1.26.0".freeze
|
7
7
|
|
8
8
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
9
9
|
s.require_paths = ["lib".freeze]
|
@@ -12,8 +12,8 @@ Gem::Specification.new do |s|
|
|
12
12
|
s.description = "This library contains some useful functionality to support the development of Ruby Gems".freeze
|
13
13
|
s.email = "flori@ping.de".freeze
|
14
14
|
s.executables = ["gem_hadar".freeze]
|
15
|
-
s.extra_rdoc_files = ["README.md".freeze, "lib/gem_hadar.rb".freeze, "lib/gem_hadar/github.rb".freeze, "lib/gem_hadar/setup.rb".freeze, "lib/gem_hadar/template_compiler.rb".freeze, "lib/gem_hadar/version.rb".freeze]
|
16
|
-
s.files = [".gitignore".freeze, "Gemfile".freeze, "LICENSE".freeze, "README.md".freeze, "Rakefile".freeze, "VERSION".freeze, "bin/gem_hadar".freeze, "gem_hadar.gemspec".freeze, "lib/gem_hadar.rb".freeze, "lib/gem_hadar/github.rb".freeze, "lib/gem_hadar/setup.rb".freeze, "lib/gem_hadar/template_compiler.rb".freeze, "lib/gem_hadar/version.rb".freeze]
|
15
|
+
s.extra_rdoc_files = ["README.md".freeze, "lib/gem_hadar.rb".freeze, "lib/gem_hadar/github.rb".freeze, "lib/gem_hadar/prompt_template.rb".freeze, "lib/gem_hadar/setup.rb".freeze, "lib/gem_hadar/template_compiler.rb".freeze, "lib/gem_hadar/utils.rb".freeze, "lib/gem_hadar/version.rb".freeze]
|
16
|
+
s.files = [".gitignore".freeze, "Gemfile".freeze, "LICENSE".freeze, "README.md".freeze, "Rakefile".freeze, "VERSION".freeze, "bin/gem_hadar".freeze, "gem_hadar.gemspec".freeze, "lib/gem_hadar.rb".freeze, "lib/gem_hadar/github.rb".freeze, "lib/gem_hadar/prompt_template.rb".freeze, "lib/gem_hadar/setup.rb".freeze, "lib/gem_hadar/template_compiler.rb".freeze, "lib/gem_hadar/utils.rb".freeze, "lib/gem_hadar/version.rb".freeze]
|
17
17
|
s.homepage = "https://github.com/flori/gem_hadar".freeze
|
18
18
|
s.licenses = ["MIT".freeze]
|
19
19
|
s.rdoc_options = ["--title".freeze, "GemHadar - Library for the development of Ruby Gems".freeze, "--main".freeze, "README.md".freeze]
|
@@ -22,10 +22,11 @@ Gem::Specification.new do |s|
|
|
22
22
|
|
23
23
|
s.specification_version = 4
|
24
24
|
|
25
|
-
s.add_development_dependency(%q<gem_hadar>.freeze, ["~> 1.
|
25
|
+
s.add_development_dependency(%q<gem_hadar>.freeze, ["~> 1.26".freeze])
|
26
26
|
s.add_runtime_dependency(%q<tins>.freeze, ["~> 1.0".freeze])
|
27
27
|
s.add_runtime_dependency(%q<term-ansicolor>.freeze, ["~> 1.0".freeze])
|
28
28
|
s.add_runtime_dependency(%q<ollama-ruby>.freeze, ["~> 1.0".freeze])
|
29
|
+
s.add_runtime_dependency(%q<mize>.freeze, [">= 0".freeze])
|
29
30
|
s.add_runtime_dependency(%q<rake>.freeze, [">= 0".freeze])
|
30
31
|
s.add_runtime_dependency(%q<yard>.freeze, [">= 0".freeze])
|
31
32
|
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
module GemHadar::PromptTemplate
|
2
|
+
# The default_git_release_system_prompt method returns the system prompt used
|
3
|
+
# for generating GitHub release changelogs.
|
4
|
+
#
|
5
|
+
# This prompt instructs the AI model to act as a Ruby programmer who creates
|
6
|
+
# markdown-formatted changelog entries for new releases. The generated
|
7
|
+
# content helps users understand what has changed in the software.
|
8
|
+
#
|
9
|
+
# @return [ String ] the system prompt for GitHub release changelog generation
|
10
|
+
def default_git_release_system_prompt
|
11
|
+
<<~EOT
|
12
|
+
You are a Ruby programmer generating changelog messages in markdown
|
13
|
+
format for new releases, so users can see what has changed. Remember you
|
14
|
+
are not a chatbot of any kind.
|
15
|
+
EOT
|
16
|
+
end
|
17
|
+
|
18
|
+
# The default_git_release_prompt method returns the prompt used for
|
19
|
+
# generating GitHub release changelogs.
|
20
|
+
#
|
21
|
+
# This prompt instructs the AI model to create a markdown-formatted changelog
|
22
|
+
# entry for a new release. It specifies guidelines for what constitutes
|
23
|
+
# significant changes, emphasizing the exclusion of trivial updates
|
24
|
+
# and the inclusion of only verified and impactful modifications.
|
25
|
+
#
|
26
|
+
# @return [ String ] the prompt template for GitHub release changelog generation
|
27
|
+
def default_git_release_prompt
|
28
|
+
<<~EOT
|
29
|
+
Output the content of a changelog for the new release of %{name} %{version}
|
30
|
+
|
31
|
+
**Strictly** follow these guidelines:
|
32
|
+
|
33
|
+
- Use bullet points in markdown format (`-`) to list significant changes.
|
34
|
+
- Exclude trivial updates such as:
|
35
|
+
* Version number increments
|
36
|
+
* Dependency version bumps (unless they resolve critical issues)
|
37
|
+
* Minor code style adjustments
|
38
|
+
* Internal documentation tweaks
|
39
|
+
- Include only verified and substantial changes that impact
|
40
|
+
functionality, performance, or user experience.
|
41
|
+
- If unsure about a change's significance, omit it from the output.
|
42
|
+
- Avoid adding any comments or notes; keep the output purely factual.
|
43
|
+
|
44
|
+
These are the log messages including patches for the new release:
|
45
|
+
|
46
|
+
%{log_diff}
|
47
|
+
EOT
|
48
|
+
end
|
49
|
+
|
50
|
+
# The default_version_bump_system_prompt method returns the system prompt
|
51
|
+
# used for generating semantic version bump suggestions.
|
52
|
+
#
|
53
|
+
# This prompt instructs the AI model to act as an expert in semantic versioning,
|
54
|
+
# analyzing provided changes and determining whether a major, minor, or build
|
55
|
+
# version bump is appropriate. It requires the model to provide a brief
|
56
|
+
# explanation of its reasoning followed by a single line containing only one
|
57
|
+
# word: 'major', 'minor', or 'build'.
|
58
|
+
#
|
59
|
+
# @return [ String ] the system prompt for semantic version bump suggestion generation
|
60
|
+
def default_version_bump_system_prompt
|
61
|
+
<<~EOT
|
62
|
+
You are an expert at semantic versioning. Analyze the provided changes
|
63
|
+
and suggest whether to bump major, minor, or build version according to
|
64
|
+
Semantic Versioning. Provide a brief explanation of your reasoning,
|
65
|
+
followed by a single line containing only one word: 'major', 'minor', or
|
66
|
+
'build'.
|
67
|
+
EOT
|
68
|
+
end
|
69
|
+
|
70
|
+
# The default_version_bump_prompt method returns the prompt template used for
|
71
|
+
# generating semantic version bump suggestions.
|
72
|
+
#
|
73
|
+
# This prompt instructs the AI model to analyze provided changes and
|
74
|
+
# determine whether a major, minor, or build version bump is appropriate
|
75
|
+
# according to Semantic Versioning principles. It requires the model to first
|
76
|
+
# provide a brief explanation of its reasoning, followed by a single line
|
77
|
+
# containing only one word: 'major', 'minor', or 'build'.
|
78
|
+
#
|
79
|
+
# @return [ String ] the prompt template for semantic version bump suggestion generation
|
80
|
+
def default_version_bump_prompt
|
81
|
+
<<~EOT
|
82
|
+
Given the current version %{version} and the following changes:
|
83
|
+
|
84
|
+
%{log_diff}
|
85
|
+
|
86
|
+
Please explain your reasoning for suggesting a version bump and then end
|
87
|
+
with a single line containing only one word: 'major', 'minor', or
|
88
|
+
'build'.
|
89
|
+
EOT
|
90
|
+
end
|
91
|
+
end
|
data/lib/gem_hadar/setup.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
class GemHadar::Setup
|
2
2
|
include FileUtils
|
3
3
|
|
4
|
+
# The perform method sets up the basic project structure by creating the lib
|
5
|
+
# directory, initializing a VERSION file with '0.0.0' if it doesn't exist,
|
6
|
+
# and creating a default Rakefile with basic GemHadar configuration if one
|
7
|
+
# doesn't already exist.
|
4
8
|
def perform
|
5
9
|
mkdir_p 'lib'
|
6
10
|
unless File.exist?('VERSION')
|
@@ -4,12 +4,26 @@ class GemHadar::TemplateCompiler
|
|
4
4
|
include Tins::BlockSelf
|
5
5
|
include Tins::MethodMissingDelegator::DelegatorModule
|
6
6
|
|
7
|
+
# The initialize method sets up the template compiler instance by evaluating
|
8
|
+
# the provided block in the context of the object.
|
9
|
+
#
|
10
|
+
# @param block [ Proc ] the block to be evaluated for configuring the template compiler
|
7
11
|
def initialize(&block)
|
8
12
|
super block_self(&block)
|
9
13
|
@values = {}
|
10
14
|
instance_eval(&block)
|
11
15
|
end
|
12
16
|
|
17
|
+
# The compile method processes an ERB template file and writes the rendered
|
18
|
+
# output to a destination file.
|
19
|
+
#
|
20
|
+
# This method reads the content of a source file, treats it as an ERB
|
21
|
+
# template, and renders it using the provided binding.
|
22
|
+
# The result is then written to a specified destination file, effectively
|
23
|
+
# generating a new file based on the template.
|
24
|
+
#
|
25
|
+
# @param src [ String ] the path to the source ERB template file
|
26
|
+
# @param dst [ String ] the path to the destination file where the rendered content will be written
|
13
27
|
def compile(src, dst)
|
14
28
|
template = File.read(src)
|
15
29
|
File.open(dst, 'w') do |output|
|
@@ -19,6 +33,21 @@ class GemHadar::TemplateCompiler
|
|
19
33
|
end
|
20
34
|
end
|
21
35
|
|
36
|
+
# The method_missing method handles dynamic attribute access and assignment.
|
37
|
+
#
|
38
|
+
# This method intercepts calls to undefined methods on the object, allowing
|
39
|
+
# for dynamic retrieval and setting of values through method calls. If a
|
40
|
+
# method name corresponds to a key in @values and no arguments are provided,
|
41
|
+
# it returns the stored value. If a single argument is provided, it stores
|
42
|
+
# the argument under the method name as a key in @values. For all other
|
43
|
+
# cases, it delegates the call to the superclass implementation.
|
44
|
+
#
|
45
|
+
# @param id [ Symbol ] the name of the method being called
|
46
|
+
# @param a [ Array ] the arguments passed to the method
|
47
|
+
# @param b [ Proc ] the block passed to the method
|
48
|
+
#
|
49
|
+
# @return [ Object ] the value associated with the method name if retrieving,
|
50
|
+
# otherwise delegates to super
|
22
51
|
def method_missing(id, *a, &b)
|
23
52
|
if a.empty? && id && @values.key?(id)
|
24
53
|
@values[id]
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module GemHadar::Utils
|
2
|
+
# The xdg_config_filename method constructs the full path to a configuration
|
3
|
+
# file based on the XDG Base Directory specification.
|
4
|
+
#
|
5
|
+
# It first checks if the XDG_CONFIG_HOME environment variable is set and not
|
6
|
+
# empty. If it is set, the method joins this directory with the provided
|
7
|
+
# filename to form the complete path. If XDG_CONFIG_HOME is not set, it
|
8
|
+
# defaults to using the HOME environment variable to construct the path
|
9
|
+
# within the standard .config directory.
|
10
|
+
#
|
11
|
+
# @param name [ String ] the name of the configuration file
|
12
|
+
#
|
13
|
+
# @return [ String ] the full path to the configuration file
|
14
|
+
def xdg_config_filename(name)
|
15
|
+
if xdg = ENV['XDG_CONFIG_HOME'].full?
|
16
|
+
File.join(xdg, name)
|
17
|
+
else
|
18
|
+
File.join(ENV.fetch('HOME'), '.config', name)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
memoize method:
|
23
|
+
# The xdg_config method retrieves configuration data from a file following
|
24
|
+
# the XDG Base Directory specification.
|
25
|
+
#
|
26
|
+
# It checks for the existence of a configuration file using the
|
27
|
+
# xdg_config_filename method and returns its contents if found. If the file
|
28
|
+
# does not exist, it returns the provided default value instead.
|
29
|
+
#
|
30
|
+
# @param name [ String ] the name of the configuration file to retrieve
|
31
|
+
# @param default [ Object ] the default value to return if the configuration file is not found
|
32
|
+
#
|
33
|
+
# @return [ String ] the content of the configuration file or the default value
|
34
|
+
def xdg_config(name, default)
|
35
|
+
if File.exist?(xdg_config_filename(name))
|
36
|
+
File.read(xdg_config_filename(name))
|
37
|
+
else
|
38
|
+
default
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|