From 36a835239d210ef0ad37521a2c8642762cf5d492 Mon Sep 17 00:00:00 2001 From: Zeke Gabrielse Date: Fri, 9 Aug 2024 08:01:32 -0500 Subject: [PATCH] add docs --- README.md | 125 ++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 112 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index b1d5366..e4772ab 100644 --- a/README.md +++ b/README.md @@ -1,31 +1,130 @@ -# TemporaryTables +# temporary_tables -TODO: Delete this and the text below, and describe your gem +[![CI](https://github.com/keygen-sh/temporary_tables/actions/workflows/test.yml/badge.svg)](https://github.com/keygen-sh/temporary_tables/actions) +[![Gem Version](https://badge.fury.io/rb/temporary_tables.svg)](https://badge.fury.io/rb/temporary_tables) -Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/temporary_tables`. To experiment with that code, run `bin/console` for an interactive prompt. +Use `temporary_tables` to create temporary tables and models in RSpec specs, +rather than create and maintain a dummy Rails application. + +This gem was extracted from [Keygen](https://keygen.sh). + +Sponsored by: + + +
+ Keygen +
+
+ +_A fair source software licensing and distribution API._ ## Installation -TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org. +Add this line to your application's `Gemfile`: + +```ruby +gem 'temporary_tables' +``` -Install the gem and add to the application's Gemfile by executing: +And then execute: - $ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG +```bash +$ bundle +``` -If bundler is not being used to manage dependencies, install the gem by executing: +Or install it yourself as: - $ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG +```bash +$ gem install temporary_tables +``` ## Usage -TODO: Write usage instructions here +### `temporary_table` + +To define a temporary table: + +```ruby +describe Example do + temporary_table :user do |t| + t.string :email + t.string :first_name + t.string :last_name + t.index :email, unique: true + end + + it 'should define a table' do + expect(ActiveRecord::Base.connection.table_exists?(:user)).to be true + end +end +``` + +The full Active Record schema API is available. + +### `temporary_model` + +To define an Active Record: + +```ruby +describe Example do + temporary_model :user do + has_many :posts + end -## Development + it 'should define a record' do + expect(const_defined?(:User)).to be true + end +end +``` -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. +To define an Active Model: -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). +```ruby +describe Example do + temporary_model :guest_user, table_name: nil, base_class: nil do + include ActiveModel::Model + end + + it 'should define a model' do + expect(const_defined?(:GuestUser)).to be true + end +end +``` + +To define a PORO: + +```ruby +describe Example do + temporary_model :null_user, table_name: nil, base_class: nil do + # ... + end + + it 'should define a PORO' do + expect(const_defined?(:NullUser)).to be true + end +end +``` + +## Future + +Right now, the gem only supports RSpec, but we're open to pull requests that +extend the functionality to other testing frameworks. + +## Supported Rubies + +**`temporary_tables` supports Ruby 3.1 and above.** We encourage you to upgrade +if you're on an older version. Ruby 3 provides a lot of great features, like +better pattern matching and a new shorthand hash syntax. + +## Is it any good? + +Yes. ## Contributing -Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/temporary_tables. +If you have an idea, or have discovered a bug, please open an issue or create a +pull request. + +## License + +The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).