aasm_rbs 0.1.0 → 0.2.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 +23 -1
- data/exe/aasm_rbs +6 -0
- data/lib/aasm_rbs/version.rb +1 -1
- data/lib/aasm_rbs.rb +18 -0
- data/sig/aasm_rbs.rbs +3 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5ddfc302bf61720f7444bbd35a41071341e1bccf688c1c2132c3e87545360125
|
4
|
+
data.tar.gz: d4b4678955f896fef85efd6d9011563df8f09c79d36e84979f22d4f009a226ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb93b9cf0fa7a90dc315ebcf13d48cab132539f01cd4235784e16224a6ea6fe8dd72834e083f561e54d341399d00647ccb11305d18ce7a4c7e3dd7a4a6588566
|
7
|
+
data.tar.gz: a0488476811cd0bcc2a1aefddd06c96a34ade62c8aeb797d8df7aea13354111b72f8a002a0a91a612015376010f2332217408513123658bcc55967f54b45b9ae
|
data/README.md
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
# AASM RBS Generator
|
2
|
+
|
3
|
+
[](https://badge.fury.io/rb/aasm_rbs) [](https://rubygems.org/gems/aasm_rbs) [](https://github.com/Uaitt/aasm_rbs/actions/workflows/linters.yml) [](https://github.com/Uaitt/aasm_rbs/actions/workflows/specs.yml)
|
4
|
+
|
2
5
|
Easily generate RBS signatures for all the AASM automatically generated methods and constants of your ruby classes.
|
3
6
|
|
4
7
|
## Description
|
@@ -26,11 +29,30 @@ gem 'aasm_rbs'
|
|
26
29
|
Then, execute `bundle install` in order to load the gem's code.
|
27
30
|
|
28
31
|
## Usage
|
32
|
+
At the moment AASM RBS only supports pure-ruby projects or Rails applications.
|
33
|
+
|
34
|
+
This gem assumes that your project is arranged with a traditional structure:
|
35
|
+
- If dealing with a Rails app, your classes should be in any folder nested inside of `app/` or `lib/`
|
36
|
+
- If dealing with a Ruby project, your actual classes should go inside of `lib/` and arranged as:
|
37
|
+
```
|
38
|
+
lib/
|
39
|
+
├── foo/
|
40
|
+
│ ├── bar.rb # contains Foo::Bar
|
41
|
+
│ ├── baz.rb # contains Foo::Baz
|
42
|
+
│── foo.rb # contains Foo
|
43
|
+
```
|
44
|
+
|
45
|
+
For more information about how to structure your projects, take a look at the following articles:
|
46
|
+
- [Autoloading and reloading constants](https://guides.rubyonrails.org/autoloading_and_reloading_constants.html) from the Rails guides
|
47
|
+
- [Exploring the structure of a Ruby gem](https://www.cloudbees.com/blog/exploring-structure-ruby-gems) fantastic article from cloudbees (a little bit old but still relevant)
|
48
|
+
|
29
49
|
Generating the RBS signatures is as easy as launching the following command from the command-line:
|
30
50
|
```
|
31
|
-
bundle exec aasm_rbs ClassName
|
51
|
+
bundle exec aasm_rbs Namespace::ClassName
|
32
52
|
```
|
33
53
|
|
54
|
+
If your class is namespaced inside of other modules/classes, please pass the whole name as you see in the previous command to AASM RBS or it won't be able to infer the path.
|
55
|
+
|
34
56
|
The generated signatures will appear in `stdout`.
|
35
57
|
|
36
58
|
|
data/exe/aasm_rbs
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
+
unless File.exist?('./Rakefile') || File.exist?('./Gemfile')
|
4
|
+
abort 'Please run aasm_rbs from the project root.'
|
5
|
+
end
|
6
|
+
|
3
7
|
require_relative '../lib/aasm_rbs'
|
4
8
|
|
9
|
+
AasmRbs.load_constants(ARGV[0] || '')
|
10
|
+
|
5
11
|
$stdout.puts ''
|
6
12
|
$stdout.puts AasmRbs.run(ARGV[0] || '')
|
7
13
|
$stdout.puts ''
|
data/lib/aasm_rbs/version.rb
CHANGED
data/lib/aasm_rbs.rb
CHANGED
@@ -3,6 +3,24 @@
|
|
3
3
|
require_relative 'aasm_rbs/output'
|
4
4
|
|
5
5
|
module AasmRbs
|
6
|
+
def self.load_constants(klass_name)
|
7
|
+
load './Rakefile' if File.exist?('./Rakefile')
|
8
|
+
begin
|
9
|
+
Rake::Task[:environment].invoke
|
10
|
+
rescue StandardError
|
11
|
+
nil
|
12
|
+
end
|
13
|
+
return if defined?(Rails)
|
14
|
+
|
15
|
+
# not in a Rails project, load the file manually
|
16
|
+
file = Dir.pwd + "/lib/#{klass_name.split('::').join('/').downcase}"
|
17
|
+
begin
|
18
|
+
require file
|
19
|
+
rescue LoadError
|
20
|
+
abort 'There was a problem loading the class file'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
6
24
|
def self.run(klass_name)
|
7
25
|
klass = Object.const_get(klass_name)
|
8
26
|
states = klass.aasm.states.map(&:name)
|
data/sig/aasm_rbs.rbs
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aasm_rbs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lorenzo Zabot
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-08-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aasm
|