Skip to content

Commit f623bb7

Browse files
committed
gem init
1 parent 456e8b8 commit f623bb7

13 files changed

Lines changed: 301 additions & 0 deletions

File tree

‎.github/workflows/rspec.yml‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: RSpec
2+
3+
on:
4+
- pull_request
5+
- push
6+
7+
jobs:
8+
rspec:
9+
name: RSpec
10+
runs-on: ubuntu-latest
11+
strategy:
12+
matrix:
13+
ruby-version:
14+
- "3.3"
15+
- "3.4"
16+
steps:
17+
- uses: actions/checkout@v6
18+
- uses: ruby/setup-ruby@v1
19+
with:
20+
bundler-cache: true
21+
ruby-version: ${{ matrix.ruby-version }}
22+
- run: bundle exec rake

‎.gitignore‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/.bundle/
2+
/.yardoc
3+
/_yardoc/
4+
/coverage/
5+
/doc/
6+
/pkg/
7+
/spec/reports/
8+
/tmp/
9+
10+
# rspec failure tracking
11+
.rspec_status
12+
13+
# rbenv version
14+
.ruby-version
15+
16+
Gemfile.lock

‎.rspec‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
--format documentation
2+
--color
3+
--require spec_helper

‎.rubocop.yml‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
AllCops:
2+
TargetRubyVersion: 3.1
3+
4+
Style/StringLiterals:
5+
EnforcedStyle: single_quotes
6+
7+
Style/StringLiteralsInInterpolation:
8+
EnforcedStyle: single_quotes

‎Gemfile‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# frozen_string_literal: true
2+
3+
source 'https://rubygems.org'
4+
5+
gemspec
6+
7+
gem 'irb'
8+
gem 'rake'
9+
gem 'rspec'
10+
gem 'rubocop'

‎README.md‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Rails::Compose
2+
3+
TODO: Delete this and the text below, and describe your gem
4+
5+
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/rails/compose`. To experiment with that code, run `bin/console` for an interactive prompt.
6+
7+
## Installation
8+
9+
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.
10+
11+
Install the gem and add to the application's Gemfile by executing:
12+
13+
```bash
14+
bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
15+
```
16+
17+
If bundler is not being used to manage dependencies, install the gem by executing:
18+
19+
```bash
20+
gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
21+
```
22+
23+
## Usage
24+
25+
TODO: Write usage instructions here
26+
27+
## Development
28+
29+
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.
30+
31+
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).
32+
33+
## Contributing
34+
35+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rails-compose.

‎Rakefile‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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+
task default: %i[spec rubocop]

‎compose.gemspec‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# frozen_string_literal: true
2+
3+
require_relative 'lib/compose/version'
4+
5+
Gem::Specification.new do |spec|
6+
spec.name = 'compose'
7+
spec.version = Compose::VERSION
8+
spec.authors = ['Alexander Mancevice']
9+
spec.email = ['a.mancevice@kickstarter.com']
10+
11+
spec.summary = 'Helper to use Docker Compose services with Rails'
12+
spec.description = 'Find dynamically allocated ports for services with Docker Compose'
13+
spec.homepage = 'https://github.com/kickstarter/rails-compose'
14+
spec.required_ruby_version = '>= 3.1.0'
15+
16+
spec.metadata['allowed_push_host'] = nil
17+
18+
spec.metadata['homepage_uri'] = spec.homepage
19+
spec.metadata['source_code_uri'] = 'https://github.com/kickstarter/rails-compose'
20+
spec.metadata['changelog_uri'] = 'https://github.com/kickstarter/rails-compose/releases'
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+
gemspec = File.basename(__FILE__)
25+
spec.files = IO.popen(%w[git ls-files -z], chdir: __dir__, err: IO::NULL) do |ls|
26+
ls.readlines("\x0", chomp: true).reject do |f|
27+
(f == gemspec) ||
28+
f.start_with?(*%w[bin/ test/ spec/ features/ .git appveyor Gemfile])
29+
end
30+
end
31+
spec.bindir = 'exe'
32+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
33+
spec.require_paths = ['lib']
34+
35+
# Uncomment to register a new dependency of your gem
36+
# spec.add_dependency "example-gem", "~> 1.0"
37+
38+
# For more information and examples about making a new gem, check out our
39+
# guide at: https://bundler.io/guides/creating_gem.html
40+
end

‎lib/compose.rb‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# frozen_string_literal: true
2+
3+
require 'json'
4+
5+
require_relative 'compose/version'
6+
7+
##
8+
# Your one-stop shop for local development needs
9+
module Compose
10+
def self.execute(*args)
11+
`docker compose #{args.join ' '}`.chomp
12+
end
13+
14+
def self.port(service, port, template = nil)
15+
return unless enabled?
16+
17+
port = ports.dig(service.to_s, port.to_s)
18+
port && template ? template % port : port
19+
end
20+
21+
def self.ports
22+
@ports ||= begin
23+
# Get raw text block for service|ports
24+
result = enabled? ? execute(:ps, '--format', 'json') : ''
25+
26+
# Parse results
27+
result.each_line.to_h do |line|
28+
data = JSON.parse(line).slice('Service', 'Publishers')
29+
name = data['Service']
30+
values = data['Publishers'].to_h { |pub| pub.slice('TargetPort', 'PublishedPort').values.map(&:to_s) }
31+
32+
[name, values]
33+
end
34+
end
35+
end
36+
37+
def self.enabled?
38+
ENV['RAILS_DISABLE_COMPOSE'].nil? || ENV['RAILS_DISABLE_COMPOSE'] == ''
39+
end
40+
end

‎lib/compose/ps.rb‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# frozen_string_literal: true
2+
3+
module Compose
4+
##
5+
# Heper to parse `docker compose ps` output
6+
module PS
7+
end
8+
end

0 commit comments

Comments
 (0)