uniformity 0.2.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +22 -12
- data/lib/generators/uniformity/USAGE +18 -0
- data/lib/generators/uniformity/engine.rb +27 -0
- data/lib/generators/uniformity/templates/engine_root/%application_name%-%singular_name%.gemspec.tt +20 -0
- data/lib/generators/uniformity/templates/engine_root/Gemfile.tt +13 -0
- data/lib/generators/uniformity/templates/engine_root/README.md.tt +22 -0
- data/lib/generators/uniformity/templates/engine_root/Rakefile.tt +36 -0
- data/lib/generators/uniformity/templates/engine_root/app/assets/images/%application_name%/%singular_name%/.gitkeep +0 -0
- data/lib/generators/uniformity/templates/engine_root/app/assets/stylesheets/%application_name%/%singular_name%/application.scss.tt +2 -0
- data/lib/generators/uniformity/templates/engine_root/app/controllers/%application_name%/%singular_name%/application_controller.rb.tt +6 -0
- data/lib/generators/uniformity/templates/engine_root/app/controllers/%application_name%/%singular_name%/webhooks_controller.rb.tt +9 -0
- data/lib/generators/uniformity/templates/engine_root/app/jobs/%application_name%/%singular_name%/application_job.rb.tt +7 -0
- data/lib/generators/uniformity/templates/engine_root/app/jobs/%application_name%/%singular_name%/hello_world_job.rb.tt +9 -0
- data/lib/generators/uniformity/templates/engine_root/app/mailers/%application_name%/%singular_name%/mailer.rb.tt +6 -0
- data/lib/generators/uniformity/templates/engine_root/app/models/%application_name%/%singular_name%/application_record.rb.tt +7 -0
- data/lib/generators/uniformity/templates/engine_root/app/views/%application_name%/%singular_name%/.gitkeep +0 -0
- data/lib/generators/uniformity/templates/engine_root/bin/console.tt +14 -0
- data/lib/generators/uniformity/templates/engine_root/bin/rails.tt +14 -0
- data/lib/generators/uniformity/templates/engine_root/config/locales/nl.yml.tt +3 -0
- data/lib/generators/uniformity/templates/engine_root/config/routes.rb.tt +3 -0
- data/lib/generators/uniformity/templates/engine_root/lib/%application_name%/%singular_name%/configuration.rb.tt +25 -0
- data/lib/generators/uniformity/templates/engine_root/lib/%application_name%/%singular_name%/engine.rb.tt +20 -0
- data/lib/generators/uniformity/templates/engine_root/lib/%application_name%/%singular_name%/version.rb.tt +5 -0
- data/lib/generators/uniformity/templates/engine_root/lib/%application_name%/%singular_name%.rb.tt +20 -0
- data/lib/generators/uniformity/templates/engine_root/lib/%application_name%/tasks/%application_name%/%singular_name%.rake.tt +9 -0
- data/lib/generators/uniformity/templates/initializer.rb +4 -0
- data/lib/uniformity/version.rb +1 -1
- metadata +27 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ff57972dd210d6a4b81e74640cad67e64576991069151c6ea8de2919258284d
|
4
|
+
data.tar.gz: 283fd4a346aad44a97bc622f3e12e34e1b5152f02f521ac2c9f1932d8e9d4c4e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e0b6d7e9a6860348e4a2b98723b9bc2bf5015e7b99b8857940573cad2375c1162a7f43209a6c95d206723fbbeada431f55a15bc13f2acf02cce0829e111a16d
|
7
|
+
data.tar.gz: 2b9372ecf38dbd60ff9abb69ce7356d83e4047599e51620b3b06fc5021082a2eae5d9090990a1f73b341913ac8442ac7bd7a0e131d0c474baaef5edb9e7d9fdf
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,39 +1,49 @@
|
|
1
1
|
# Uniformity
|
2
2
|
|
3
|
+
Generates an Engine for any external service you're using in a Ruby on Rails application.
|
4
|
+
|
5
|
+
The engine should contain all your code specific to the service. Now your main application is free of an untold number of implicit dependencies. Instead, it has just one: the engine that neatly sits inside the application's folder. Ditch the service by ditching _only_ the engine. Never wonder where any change in relation to the service should go.
|
6
|
+
|
7
|
+
The beauty of this approach is that the engine behaves just a regular Rails application, with all the familiar folders for models, controllers, views, jobs, etcetera. The generated engine is namespaced so that it never clashes with any official Gem provided by the service. It also follows best practices so you don't have to.
|
3
8
|
|
4
9
|
## Installation
|
5
10
|
|
6
11
|
Add this line to your application's Gemfile:
|
7
12
|
|
8
13
|
```ruby
|
9
|
-
gem 'uniformity'
|
14
|
+
gem 'uniformity', group: :development
|
10
15
|
```
|
11
16
|
|
12
17
|
And then execute:
|
13
18
|
|
14
19
|
$ bundle
|
15
20
|
|
16
|
-
|
21
|
+
## Usage
|
17
22
|
|
18
|
-
|
23
|
+
Imagine you want to use the fictional external service `Space Babies`. Run this command:
|
19
24
|
|
20
|
-
|
25
|
+
```
|
26
|
+
rails generate uniformity:space_babies
|
27
|
+
```
|
21
28
|
|
29
|
+
Put all the code using this service in the `engines/space_babies` directory. Use any Rails design pattern you need. A few empty classes using the correct namespace are generated for you as a starting point.
|
22
30
|
|
23
|
-
|
31
|
+
### Dependencies
|
24
32
|
|
25
|
-
|
33
|
+
If your code depends on a gem, put those in the engine's `gemspec` and not in your main app. Make sure your main app has just the one dependency on the engine.
|
26
34
|
|
27
|
-
|
35
|
+
After generatin', you can remove Uniformity from your Gemfile if you want. The generated engine has no dependencies whatsoever, outside from Rails. There is no harm in leaving Uniformity enabled either, since it has no run-time code.
|
28
36
|
|
29
37
|
## Contributing
|
30
38
|
|
31
|
-
|
39
|
+
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/spacebabies/uniformity/blob/master/CODE_OF_CONDUCT.md).
|
32
40
|
|
33
|
-
|
41
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/spacebabies/uniformity.
|
34
42
|
|
35
|
-
|
43
|
+
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.
|
36
44
|
|
37
|
-
|
45
|
+
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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
38
46
|
|
39
|
-
|
47
|
+
## License
|
48
|
+
|
49
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
@@ -0,0 +1,18 @@
|
|
1
|
+
Description:
|
2
|
+
Wrap any external service with an Engine.
|
3
|
+
|
4
|
+
Example:
|
5
|
+
Let's say your Rails application wants to send email using Postmark API.
|
6
|
+
|
7
|
+
Generate an engine to contain all code related to this interface:
|
8
|
+
rails generate uniformity:engine Postmark
|
9
|
+
|
10
|
+
This will create:
|
11
|
+
engines/<your_application>-postmark/app
|
12
|
+
engines/<your_application>-postmark/bin
|
13
|
+
engines/<your_application>-postmark/config
|
14
|
+
engines/<your_application>-postmark/lib
|
15
|
+
engines/<your_application>-postmark/Gemfile
|
16
|
+
engines/<your_application>-postmark/<your_application>-postmark.gemspec
|
17
|
+
engines/<your_application>-postmark/Rakefile
|
18
|
+
engines/<your_application>-postmark/README.md
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Uniformity
|
2
|
+
class EngineGenerator < ::Rails::Generators::NamedBase
|
3
|
+
source_root File.expand_path('templates', __dir__)
|
4
|
+
|
5
|
+
def add_engine_files
|
6
|
+
directory "engine_root", "engines/#{application_name}-#{singular_name}"
|
7
|
+
template "initializer.rb", "config/initializers/#{application_name}_#{singular_name}.rb"
|
8
|
+
end
|
9
|
+
|
10
|
+
def bundle_engine
|
11
|
+
gem "#{application_name}-#{singular_name}", path: "engines/#{application_name}-#{singular_name}"
|
12
|
+
run "bundle install"
|
13
|
+
end
|
14
|
+
|
15
|
+
def mount_engine
|
16
|
+
route "mount #{application_const_base}::#{class_name}.engine, at: '#{singular_name}'"
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def application_const_base
|
22
|
+
if defined?(Rails) && Rails.application
|
23
|
+
Rails.application.class.name.split("::").first
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/generators/uniformity/templates/engine_root/%application_name%-%singular_name%.gemspec.tt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
2
|
+
|
3
|
+
# Maintain your gem's version:
|
4
|
+
require "<%= application_name %>/<%= singular_name %>/version"
|
5
|
+
|
6
|
+
# Describe your gem and declare its dependencies:
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = "<%= application_name %>-<%= singular_name %>"
|
9
|
+
s.version = <%= application_const_base %>::<%= class_name %>::VERSION
|
10
|
+
s.authors = ["Joost Baaij"]
|
11
|
+
s.email = ["joost@spacebabies.nl"]
|
12
|
+
s.homepage = "https://www.spacebabies.nl/"
|
13
|
+
s.summary = "Engine to connect <%= application_const_base %> to <%= class_name %>"
|
14
|
+
s.description = "Engine to connect <%= application_const_base %> to <%= class_name %>"
|
15
|
+
|
16
|
+
s.files = Dir["{app,config,db,lib}/**/*", "Rakefile", "README.md"]
|
17
|
+
|
18
|
+
# add your gem dependencies here
|
19
|
+
s.add_dependency "rails"
|
20
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
|
4
|
+
|
5
|
+
# Dependencies are declared in `gemspec`.
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
# The exception is any dependencies that are temporary or a work in progress.
|
9
|
+
# They should go in this file during development.
|
10
|
+
# Remember to move these dependencies to gemspec before releasing to rubygems.org.
|
11
|
+
|
12
|
+
# To use a debugger
|
13
|
+
# gem 'byebug', group: [:development, :test]
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# <%= application_const_base %> went to meet <%= class_name %>
|
2
|
+
|
3
|
+
In this engine we've placed everything needed to facilitate this discussion.
|
4
|
+
This way, everything is neatly contained in one place.
|
5
|
+
|
6
|
+
## Usage
|
7
|
+
1. Incoming webhooks: /<mount point>/webhooks/<action_name>
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
This engine should be part of the <%= application_const_base %> Rails app.
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem '<%= application_name %>-<%= singular_name %>', path: "engines/<%= application_name %>-<%= singular_name %>"
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
```bash
|
18
|
+
$ bundle
|
19
|
+
```
|
20
|
+
|
21
|
+
## Questions?
|
22
|
+
Joost Baaij, Space Babies, joost@spacebabies.nl
|
@@ -0,0 +1,36 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = '<%= application_const_base %>::<%= class_name %>'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
|
18
|
+
load 'rails/tasks/engine.rake'
|
19
|
+
|
20
|
+
|
21
|
+
load 'rails/tasks/statistics.rake'
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
require 'bundler/gem_tasks'
|
26
|
+
|
27
|
+
require 'rake/testtask'
|
28
|
+
|
29
|
+
Rake::TestTask.new(:test) do |t|
|
30
|
+
t.libs << 'test'
|
31
|
+
t.pattern = 'test/**/*_test.rb'
|
32
|
+
t.verbose = false
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
task default: :test
|
File without changes
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require_dependency '<%= application_name %>/<%= singular_name %>/application_controller'
|
2
|
+
|
3
|
+
module <%= application_const_base %>
|
4
|
+
module <%= class_name %>
|
5
|
+
class WebhooksController < ApplicationController
|
6
|
+
protect_from_forgery with: :null_session
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
File without changes
|
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "<%= application_name %>/<%= singular_name %>"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails gems
|
3
|
+
# installed from the root of your application.
|
4
|
+
|
5
|
+
ENGINE_ROOT = File.expand_path('../..', __FILE__)
|
6
|
+
ENGINE_PATH = File.expand_path('../../lib/<%= application_name %>/<%= singular_name %>/engine', __FILE__)
|
7
|
+
APP_PATH = File.expand_path('../../test/dummy/config/application', __FILE__)
|
8
|
+
|
9
|
+
# Set up gems listed in the Gemfile.
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
|
11
|
+
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
|
12
|
+
|
13
|
+
require 'rails/all'
|
14
|
+
require 'rails/engine/commands'
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module <%= application_const_base %>
|
2
|
+
module <%= class_name %>
|
3
|
+
# Just a random example of structured data to store in here.
|
4
|
+
Credentials = Struct.new(:setting_1, :setting_2)
|
5
|
+
|
6
|
+
# Configure this engine using a block:
|
7
|
+
#
|
8
|
+
# <%= application_const_base %>::<%= class_name %>.configure do |config|
|
9
|
+
# # add your configuration settings here, e.g.:
|
10
|
+
# # config.<setting> = <value>
|
11
|
+
# end
|
12
|
+
#
|
13
|
+
# The value can be accessed with <%= application_const_base %>::<%= class_name %>.configuration.<setting>.
|
14
|
+
class Configuration
|
15
|
+
# e.g. Credentials to connect with their API.
|
16
|
+
# Defaults to looking up the values in ENV.
|
17
|
+
def credentials
|
18
|
+
@credentials ||= Credentials.new(
|
19
|
+
ENV['<%= application_name.upcase %>_<%= singular_name.upcase %>_KEY'],
|
20
|
+
ENV['<%= application_name.upcase %>_<%= singular_name.upcase %>_SECRET']
|
21
|
+
)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'rails/engine'
|
2
|
+
|
3
|
+
module <%= application_const_base %>
|
4
|
+
module <%= class_name %>
|
5
|
+
class Engine < ::Rails::Engine
|
6
|
+
isolate_namespace <%= application_const_base %>::<%= class_name %>
|
7
|
+
|
8
|
+
config.autoload_paths << File.expand_path('lib', __dir__)
|
9
|
+
|
10
|
+
config.generators do |g|
|
11
|
+
g.test_framework :rspec
|
12
|
+
g.fixture_replacement :factory_bot, dir: 'spec/factories'
|
13
|
+
end
|
14
|
+
|
15
|
+
config.after_initialize do |app|
|
16
|
+
# do something in the main app here.
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/generators/uniformity/templates/engine_root/lib/%application_name%/%singular_name%.rb.tt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require '<%= application_name %>/<%= singular_name %>/configuration'
|
2
|
+
require '<%= application_name %>/<%= singular_name %>/engine'
|
3
|
+
|
4
|
+
module <%= application_const_base %>
|
5
|
+
module <%= class_name %>
|
6
|
+
class << self
|
7
|
+
attr_accessor :configuration
|
8
|
+
|
9
|
+
# Allow configuration to be stored for this engine.
|
10
|
+
def configure
|
11
|
+
self.configuration ||= Configuration.new
|
12
|
+
yield(configuration)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.engine
|
17
|
+
Engine
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
namespace :<%= application_name %> do
|
2
|
+
namespace :<%= singular_name %> do
|
3
|
+
# Hi from the generator. You can delete this task.
|
4
|
+
desc "👋 konichi-wa everyone!"
|
5
|
+
task hello: :environment do
|
6
|
+
puts "OHAI from the <%= application_name %>-<%= singular_name %> engine!"
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
data/lib/uniformity/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uniformity
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joost Baaij
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-04-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -70,6 +70,31 @@ files:
|
|
70
70
|
- Rakefile
|
71
71
|
- bin/console
|
72
72
|
- bin/setup
|
73
|
+
- lib/generators/uniformity/USAGE
|
74
|
+
- lib/generators/uniformity/engine.rb
|
75
|
+
- lib/generators/uniformity/templates/engine_root/%application_name%-%singular_name%.gemspec.tt
|
76
|
+
- lib/generators/uniformity/templates/engine_root/Gemfile.tt
|
77
|
+
- lib/generators/uniformity/templates/engine_root/README.md.tt
|
78
|
+
- lib/generators/uniformity/templates/engine_root/Rakefile.tt
|
79
|
+
- lib/generators/uniformity/templates/engine_root/app/assets/images/%application_name%/%singular_name%/.gitkeep
|
80
|
+
- lib/generators/uniformity/templates/engine_root/app/assets/stylesheets/%application_name%/%singular_name%/application.scss.tt
|
81
|
+
- lib/generators/uniformity/templates/engine_root/app/controllers/%application_name%/%singular_name%/application_controller.rb.tt
|
82
|
+
- lib/generators/uniformity/templates/engine_root/app/controllers/%application_name%/%singular_name%/webhooks_controller.rb.tt
|
83
|
+
- lib/generators/uniformity/templates/engine_root/app/jobs/%application_name%/%singular_name%/application_job.rb.tt
|
84
|
+
- lib/generators/uniformity/templates/engine_root/app/jobs/%application_name%/%singular_name%/hello_world_job.rb.tt
|
85
|
+
- lib/generators/uniformity/templates/engine_root/app/mailers/%application_name%/%singular_name%/mailer.rb.tt
|
86
|
+
- lib/generators/uniformity/templates/engine_root/app/models/%application_name%/%singular_name%/application_record.rb.tt
|
87
|
+
- lib/generators/uniformity/templates/engine_root/app/views/%application_name%/%singular_name%/.gitkeep
|
88
|
+
- lib/generators/uniformity/templates/engine_root/bin/console.tt
|
89
|
+
- lib/generators/uniformity/templates/engine_root/bin/rails.tt
|
90
|
+
- lib/generators/uniformity/templates/engine_root/config/locales/nl.yml.tt
|
91
|
+
- lib/generators/uniformity/templates/engine_root/config/routes.rb.tt
|
92
|
+
- lib/generators/uniformity/templates/engine_root/lib/%application_name%/%singular_name%.rb.tt
|
93
|
+
- lib/generators/uniformity/templates/engine_root/lib/%application_name%/%singular_name%/configuration.rb.tt
|
94
|
+
- lib/generators/uniformity/templates/engine_root/lib/%application_name%/%singular_name%/engine.rb.tt
|
95
|
+
- lib/generators/uniformity/templates/engine_root/lib/%application_name%/%singular_name%/version.rb.tt
|
96
|
+
- lib/generators/uniformity/templates/engine_root/lib/%application_name%/tasks/%application_name%/%singular_name%.rake.tt
|
97
|
+
- lib/generators/uniformity/templates/initializer.rb
|
73
98
|
- lib/uniformity.rb
|
74
99
|
- lib/uniformity/version.rb
|
75
100
|
- uniformity.gemspec
|