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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 87a7a8d08d3f0fc893a4c567028f4580fb8c16bd34855d7a852acfa72e4af9cd
4
- data.tar.gz: 338bc773165c1d7d198fdb757c721bdb4b9729069537df45a69339adfaa5da22
3
+ metadata.gz: 5ddfc302bf61720f7444bbd35a41071341e1bccf688c1c2132c3e87545360125
4
+ data.tar.gz: d4b4678955f896fef85efd6d9011563df8f09c79d36e84979f22d4f009a226ec
5
5
  SHA512:
6
- metadata.gz: a2fa51357cfd06f334f3a10b331db7cf603ee06cb444e34aac5b3d8b6194a746b4e6b688cce6a4c07ebe541ab68cf3704c9e9fef329095c2ec88705816dea0f3
7
- data.tar.gz: 8b293ace47666124f8159ffa56f0d40ab50f8ac0c844230d98c53293b074da923ada7bcd3639f5037452f45f81d68cca5910e2353289c81ed2feaae594a4b3e0
6
+ metadata.gz: fb93b9cf0fa7a90dc315ebcf13d48cab132539f01cd4235784e16224a6ea6fe8dd72834e083f561e54d341399d00647ccb11305d18ce7a4c7e3dd7a4a6588566
7
+ data.tar.gz: a0488476811cd0bcc2a1aefddd06c96a34ade62c8aeb797d8df7aea13354111b72f8a002a0a91a612015376010f2332217408513123658bcc55967f54b45b9ae
data/README.md CHANGED
@@ -1,4 +1,7 @@
1
1
  # AASM RBS Generator
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/aasm_rbs.svg)](https://badge.fury.io/rb/aasm_rbs) [![Gem Downloads](https://badgen.net/rubygems/dt/aasm_rbs)](https://rubygems.org/gems/aasm_rbs) [![Linters](https://github.com/Uaitt/aasm_rbs/actions/workflows/linters.yml/badge.svg)](https://github.com/Uaitt/aasm_rbs/actions/workflows/linters.yml) [![Specs](https://github.com/Uaitt/aasm_rbs/actions/workflows/specs.yml/badge.svg)](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 ''
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AasmRbs
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
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
@@ -1,4 +1,7 @@
1
1
  module AasmRbs
2
+ Rake: untyped # there is yet no Rake official RBS
3
+
4
+ def self.load_constants: (String) -> void
2
5
  def self.run: (String) -> String?
3
6
  end
4
7
 
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.1.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-07-27 00:00:00.000000000 Z
11
+ date: 2023-08-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aasm