enm 0.1.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.
data/Cargo.toml ADDED
@@ -0,0 +1,13 @@
1
+ # This Cargo.toml is here to let externals tools (IDEs, etc.) know that this is
2
+ # a Rust project. Your extensions dependencies should be added to the Cargo.toml
3
+ # in the ext/ directory.
4
+
5
+ [workspace]
6
+ members = ["./ext/enm"]
7
+ resolver = "2"
8
+
9
+ [profile.release]
10
+ # By default, debug symbols are stripped from the final binary which makes it
11
+ # harder to debug if something goes wrong. It's recommended to keep debug
12
+ # symbols in the release build so that you can debug the final binary if needed.
13
+ debug = true
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026 Alexa Grey
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,78 @@
1
+ # ENM
2
+
3
+ `ENM` is a Ruby gem that allows for static analysis of PostgreSQL enum types defined a database. Presently, it only supports reading from something along the lines of Rails' `structure.sql`, but future versions may support connecting to a live database or `schema.rb`.
4
+
5
+ It relies upon the [pgenum_parser](https://crates.io/crates/pgenum_parser) crate, which it compiles against via [magnus](https://docs.rs/magnus/latest/magnus/).
6
+
7
+ ## Installation
8
+
9
+ This gem requires ruby 3.4 or later.
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ ```bash
14
+ bundle add enm
15
+ ```
16
+
17
+ If bundler is not being used to manage dependencies, install the gem by executing:
18
+
19
+ ```bash
20
+ gem install enm
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ This is intended to be used as a global singleton, so it requires a minor bit of setup in an initializer or similar:
26
+
27
+ ```ruby
28
+ require "enm"
29
+
30
+ ENM.configure_current do |builder|
31
+ builder.from_sql_file!("primary", "db/structure.sql")
32
+ end
33
+ ```
34
+
35
+ If only one database is provided, it will be used as the default for lookups.
36
+
37
+ If you have multiple databases, you can call `builder.from_sql_file!` multiple times and optionally specify which one is your default:
38
+
39
+ ```ruby
40
+ require "enm"
41
+
42
+ ENM.configure_current do |builder|
43
+ builder.from_sql_file!("primary", "db/structure.sql", default: true)
44
+ builder.from_sql_file!("analytics", "db/analytics_structure.sql")
45
+ end
46
+ ```
47
+
48
+ Once `ENM` is configured, you can look up enums in your code like so:
49
+
50
+ ```ruby
51
+ ENM.get("access_management") #=> ENM::Enum
52
+
53
+ ENM.get("some_analytics_enum", on: :analytics) #=> ENM::Enum
54
+
55
+ # To build a Dry::Types::Type for an enum:
56
+ ENM.dry("access_management") #=> Dry::Types["string"].enum("foo", "bar", "baz")
57
+
58
+ # To build a symbolized version of an enum, with a default
59
+ ENM.dry("access_management", mode: :symbol, default: :bar) #=> Dry::Types["symbol"].default(:bar).enum(:foo, :bar, :baz)
60
+ ```
61
+
62
+ ## Development
63
+
64
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
65
+
66
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
67
+
68
+ ## Contributing
69
+
70
+ Bug reports and pull requests are welcome on GitHub at https://github.com/scryptmouse/enm. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/scryptmouse/enm/blob/main/CODE_OF_CONDUCT.md).
71
+
72
+ ## License
73
+
74
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
75
+
76
+ ## Code of Conduct
77
+
78
+ Everyone interacting in the ENM project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/scryptmouse/enm/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ require "rb_sys/extensiontask"
13
+
14
+ require "yard"
15
+
16
+ YARD::Rake::YardocTask.new(:doc) do |t|
17
+ t.files = ["lib/**/*.rb"]
18
+ end
19
+
20
+ desc "Build the native extension"
21
+ task build: :compile
22
+
23
+ GEMSPEC = Gem::Specification.load("enm.gemspec")
24
+
25
+ RbSys::ExtensionTask.new("enm", GEMSPEC) do |ext|
26
+ ext.lib_dir = "lib/enm"
27
+ end
28
+
29
+ task default: %i[compile spec rubocop]
@@ -0,0 +1,22 @@
1
+ [package]
2
+ name = "enm"
3
+ version = "0.1.0"
4
+ edition = "2024"
5
+ authors = ["Alexa Grey <devel@mouse.vc>"]
6
+ license = "MIT"
7
+ publish = false
8
+
9
+ [lib]
10
+ crate-type = ["cdylib"]
11
+
12
+ [dependencies]
13
+ anyhow = "1"
14
+ magnus = { version = "0.8.2" }
15
+ pgenum_parser = { version = "0.2.1" }
16
+ rb-sys = { version = "0.9", features = ["stable-api-compiled-fallback"] }
17
+
18
+ [build-dependencies]
19
+ rb-sys-env = "0.2.2"
20
+
21
+ [dev-dependencies]
22
+ rb-sys-test-helpers = { version = "0.2.2" }
data/ext/enm/build.rs ADDED
@@ -0,0 +1,5 @@
1
+ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
2
+ let _ = rb_sys_env::activate()?;
3
+
4
+ Ok(())
5
+ }
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "mkmf"
4
+ require "rb_sys/mkmf"
5
+
6
+ create_rust_makefile("enm/enm")