Skip to content

Commit 0d8b95f

Browse files
committed
Initial Commit
0 parents  commit 0d8b95f

16 files changed

+232
-0
lines changed

.github/workflows/main.yml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Ruby
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
pull_request:
9+
10+
jobs:
11+
build:
12+
runs-on: ubuntu-latest
13+
name: Ruby ${{ matrix.ruby }}
14+
strategy:
15+
matrix:
16+
ruby:
17+
- '3.0.3'
18+
19+
steps:
20+
- uses: actions/checkout@v2
21+
- name: Set up Ruby
22+
uses: ruby/setup-ruby@v1
23+
with:
24+
ruby-version: ${{ matrix.ruby }}
25+
bundler-cache: true
26+
- name: Run the default task
27+
run: bundle exec rake

.gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/.bundle/
2+
/.yardoc
3+
/_yardoc/
4+
/coverage/
5+
/doc/
6+
/pkg/
7+
/spec/reports/
8+
/tmp/

.standard.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# For available configuration options, see:
2+
# https://github.com/testdouble/standard
3+
ruby_version: 2.6

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## [Unreleased]
2+
3+
## [0.1.0] - 2024-02-07
4+
5+
- Initial release

Gemfile

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# frozen_string_literal: true
2+
3+
source "https://rubygems.org"
4+
5+
# Specify your gem's dependencies in positioning.gemspec
6+
gemspec
7+
8+
gem "rake", "~> 13.0"
9+
10+
gem "minitest", "~> 5.0"
11+
12+
gem "standard", "~> 1.3"

LICENSE.txt

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2024 Brendon Muir
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.

README.md

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Positioning
2+
3+
The aim of this gem is to allow you to easily position model instances within a scope of your choosing. In an ideal world this gem will give your model instances sequential integer positions beginning with `1`. Attempts are made to lock the database records so that concurrent requests can't corrupt the order of items.
4+
5+
## Installation
6+
7+
Add this line to your application's Gemfile:
8+
9+
```ruby
10+
gem 'positioning'
11+
```
12+
13+
And then execute:
14+
15+
$ bundle install
16+
17+
Or install it yourself as:
18+
19+
$ gem install positioning
20+
21+
## Usage
22+
23+
Your database column should be named `position` and not allow `NULL` as a value:
24+
25+
`add_column :items, :position, :integer, null: false`
26+
27+
You should also add an index to ensure that the `position` column value is unique within its scope:
28+
29+
`add_index :items, [:list_id, :position], unique: true`
30+
31+
The above assumes that your items are scoped to a parent table called `lists`.
32+
33+
## Development
34+
35+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
36+
37+
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).
38+
39+
## Contributing
40+
41+
Bug reports and pull requests are welcome on GitHub at https://github.com/brendon/positioning.
42+
43+
## License
44+
45+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).

Rakefile

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# frozen_string_literal: true
2+
3+
require "bundler/gem_tasks"
4+
require "rake/testtask"
5+
6+
Rake::TestTask.new(:test) do |t|
7+
t.libs << "test"
8+
t.libs << "lib"
9+
t.test_files = FileList["test/**/test_*.rb"]
10+
end
11+
12+
require "standard/rake"
13+
14+
task default: %i[test standard]

bin/console

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
4+
require "bundler/setup"
5+
require "positioning"
6+
7+
# You can add fixtures and/or initialization code here to make experimenting
8+
# with your gem easier. You can also use a different console, if you like.
9+
10+
# (If you use this, don't forget to add pry to your Gemfile!)
11+
# require "pry"
12+
# Pry.start
13+
14+
require "irb"
15+
IRB.start(__FILE__)

bin/setup

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
IFS=$'\n\t'
4+
set -vx
5+
6+
bundle install
7+
8+
# Do any other automated setup that you need to do here

lib/positioning.rb

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# frozen_string_literal: true
2+
3+
require_relative "positioning/version"
4+
5+
module Positioning
6+
class Error < StandardError; end
7+
# Your code goes here...
8+
end

lib/positioning/version.rb

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# frozen_string_literal: true
2+
3+
module Positioning
4+
VERSION = "0.1.0"
5+
end

positioning.gemspec

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# frozen_string_literal: true
2+
3+
require_relative "lib/positioning/version"
4+
5+
Gem::Specification.new do |spec|
6+
spec.name = "positioning"
7+
spec.version = Positioning::VERSION
8+
spec.authors = ["Brendon Muir"]
9+
spec.email = ["[email protected]"]
10+
11+
spec.summary = "Simple positioning for Active Record models."
12+
spec.homepage = "https://github.com/brendon/positioning"
13+
spec.license = "MIT"
14+
spec.required_ruby_version = ">= 2.6.0"
15+
16+
spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
17+
18+
spec.metadata["homepage_uri"] = spec.homepage
19+
spec.metadata["source_code_uri"] = "https://github.com/brendon/positioning"
20+
spec.metadata["changelog_uri"] = "https://github.com/brendon/positioning/CHANGELOG.md"
21+
22+
# Specify which files should be added to the gem when it is released.
23+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
25+
`git ls-files -z`.split("\x0").reject do |f|
26+
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
27+
end
28+
end
29+
spec.bindir = "exe"
30+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
31+
spec.require_paths = ["lib"]
32+
33+
# Uncomment to register a new dependency of your gem
34+
spec.add_dependency "activerecord", ">= 6.1"
35+
36+
# For more information and examples about making a new gem, check out our
37+
# guide at: https://bundler.io/guides/creating_gem.html
38+
end

sig/positioning.rbs

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module Positioning
2+
VERSION: String
3+
# See the writing guide of rbs: https://github.com/ruby/rbs#guides
4+
end

test/test_helper.rb

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# frozen_string_literal: true
2+
3+
$LOAD_PATH.unshift File.expand_path("../lib", __dir__)
4+
require "positioning"
5+
6+
require "minitest/autorun"

test/test_positioning.rb

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# frozen_string_literal: true
2+
3+
require "test_helper"
4+
5+
class TestPositioning < Minitest::Test
6+
def test_that_it_has_a_version_number
7+
refute_nil ::Positioning::VERSION
8+
end
9+
10+
def test_it_does_something_useful
11+
assert false
12+
end
13+
end

0 commit comments

Comments
 (0)