appsules 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +7 -0
- data/.rubocop.yml +22 -0
- data/CHANGELOG.md +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +113 -0
- data/Rakefile +10 -0
- data/appsules.gemspec +23 -0
- data/lib/appsules.rb +44 -0
- data/lib/appsules/railtie.rb +31 -0
- data/lib/appsules/tasks/test.rake +16 -0
- data/lib/appsules/version.rb +3 -0
- metadata +85 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9e178965f61a0f02636524119f47b2d087163152
|
4
|
+
data.tar.gz: fafe647871d5dcbc29e6d4ec15b4db05bdfd3459
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7caef4fb9c7f7973f7a4017dc0004227facb12789a9ee5dd8a2acc01ec0f85be107dfa04c71c9c374f2542af8d91c7e2a3afe8f90b6ecb6adc456888f461dc1f
|
7
|
+
data.tar.gz: a096ba05feb25b266341778c7e6fc3149de91973971987468808a3c031ebac98468aba40e173955d06644a4e0159d307a9ef9bbdbce4934f0f6bb3737f9dd3f9
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2018-01-11 14:00:59 -0500 using RuboCop version 0.50.0.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 1
|
10
|
+
# Cop supports --auto-correct.
|
11
|
+
Layout/EmptyLineAfterMagicComment:
|
12
|
+
Exclude:
|
13
|
+
- 'appsules.gemspec'
|
14
|
+
|
15
|
+
# Offense count: 1
|
16
|
+
# Cop supports --auto-correct.
|
17
|
+
# Configuration parameters: AllowForAlignment, ForceEqualSignAlignment.
|
18
|
+
Metrics/LineLength:
|
19
|
+
Max: 120
|
20
|
+
|
21
|
+
Style/StringLiterals:
|
22
|
+
EnforcedStyle: double_quotes
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2016-2018 PatientsLikeMe
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
# Appsules
|
2
|
+
|
3
|
+
## Appsules? What the heck?!
|
4
|
+
|
5
|
+
Shouldn't your question be: 277 controllers and 440 models, where the heck do I begin?
|
6
|
+
|
7
|
+
### Good point. Let me rephrase: Appsules? What the heck?!
|
8
|
+
|
9
|
+
Appsules are a different way to organize your Rails app files.
|
10
|
+
|
11
|
+
Rails organizes them by architectural role: models directory, controllers directory, and so forth.
|
12
|
+
As the code base grows large it becomes hard to understand which code belongs together.
|
13
|
+
|
14
|
+
### So appsules are namespaces.
|
15
|
+
|
16
|
+
No. It's just a directory structure. There are no additional code constructs or abstractions.
|
17
|
+
|
18
|
+
### Ok, I think I get it. Appsules are like when you organize 30 books by color but after you get 300 books you are forced to organize by subject in order to find a book without losing your mind.
|
19
|
+
|
20
|
+
Yes.
|
21
|
+
|
22
|
+
### And if you decide you are no longer interested in anthropology, you can just yank out the group of seven anthropology books instead of hunting through all 300.
|
23
|
+
|
24
|
+
Yes.
|
25
|
+
|
26
|
+
## How do I create a new appsule?
|
27
|
+
|
28
|
+
Let's say you want to create a new appsule called blog. Move blog-related code from `app/` down
|
29
|
+
into `appsules/` like this, creating subdirectories as needed:
|
30
|
+
|
31
|
+
appsules/
|
32
|
+
blog/
|
33
|
+
controllers/
|
34
|
+
comments_controller.rb
|
35
|
+
posts_controller.rb
|
36
|
+
models/
|
37
|
+
comment.rb
|
38
|
+
post.rb
|
39
|
+
views/
|
40
|
+
comments/
|
41
|
+
new.html.haml
|
42
|
+
...
|
43
|
+
posts/
|
44
|
+
index.html.haml
|
45
|
+
new.html.haml
|
46
|
+
...
|
47
|
+
|
48
|
+
Leave blog code not found in `app/` (like migrations and routes) where it is.
|
49
|
+
|
50
|
+
Move all related tests and factories into `test/appsules` like so:
|
51
|
+
|
52
|
+
test/
|
53
|
+
appsules/
|
54
|
+
blog/
|
55
|
+
controllers/
|
56
|
+
comments_controller_test.rb
|
57
|
+
posts_controller_test.rb
|
58
|
+
factories/
|
59
|
+
comments.rb
|
60
|
+
posts.rb
|
61
|
+
models/
|
62
|
+
comment_test.rb
|
63
|
+
post_test.rb
|
64
|
+
|
65
|
+
## How do I appsulate all the things?
|
66
|
+
|
67
|
+
Don't go crazy; you don't need to end up with 100 tiny appsules. One place to start is
|
68
|
+
to identify [bounded contexts](http://martinfowler.com/bliki/BoundedContext.html).
|
69
|
+
|
70
|
+
## When should I create a new appsule?
|
71
|
+
|
72
|
+
When a part of your app seems separate and cohesive (like an admin section, or a search page)
|
73
|
+
then extract it out into an appsule. You can (and should!) build appsules from scratch; you
|
74
|
+
don't have to wait to extract it from existing `app/` code.
|
75
|
+
|
76
|
+
## Why wouldn't I use an engine?
|
77
|
+
|
78
|
+
Engines are another good way to break out code from a large `app/` directory. Use an engine if:
|
79
|
+
1. You expect to share the code with another application (in which case also make it a local gem).
|
80
|
+
2. or you want to have more cleanly separated code (appsules do not enforce any code boundaries).
|
81
|
+
|
82
|
+
## How do I install appsules into my Rails app?
|
83
|
+
|
84
|
+
Add this to your Gemfile:
|
85
|
+
|
86
|
+
gem 'appsules'
|
87
|
+
|
88
|
+
Then, in your `test_helper.rb` file, make sure your appsule factories get loaded:
|
89
|
+
|
90
|
+
FactoryBot.definition_file_paths = ['./factories'] # wherever you keep your factories
|
91
|
+
Appsules.add_factory_bot_paths! # add factories defined in appsules
|
92
|
+
FactoryBot.find_definitions
|
93
|
+
|
94
|
+
All of the files you put into your appsule will be automagically loaded by Rails. Also,
|
95
|
+
you'll get this cool rake task for free:
|
96
|
+
|
97
|
+
`rake test:appsule:any_appsule_name`
|
98
|
+
|
99
|
+
## What else?
|
100
|
+
|
101
|
+
This doesn't work with RSpec yet; it assumes minitest. It also assumes you are using FactoryBot.
|
102
|
+
|
103
|
+
## Contributing
|
104
|
+
|
105
|
+
1. Fork it
|
106
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
107
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
108
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
109
|
+
5. Create new pull request
|
110
|
+
|
111
|
+
## Anything else?
|
112
|
+
|
113
|
+
Yes. Leif Erikson was a Cantabrigian. I have personally seen the historical marker that proves it.
|
data/Rakefile
ADDED
data/appsules.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "appsules/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "appsules"
|
7
|
+
spec.version = Appsules::VERSION
|
8
|
+
spec.license = "MIT"
|
9
|
+
spec.authors = ["Wyatt Greene", "Michael Deutsch"]
|
10
|
+
spec.email = ["mdeutsch@patientslikeme.com"]
|
11
|
+
spec.homepage = "https://github.com/patientslikeme/appsules"
|
12
|
+
|
13
|
+
spec.summary = "Appsules are a different way to organize your Rails app files"
|
14
|
+
spec.description = spec.summary
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
16
|
+
f.match(%r{^(test|spec|features)/})
|
17
|
+
end
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_runtime_dependency "rails", "~> 5.0"
|
21
|
+
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
data/lib/appsules.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require "rails"
|
2
|
+
require "active_support"
|
3
|
+
require "active_support/core_ext"
|
4
|
+
require "appsules/railtie"
|
5
|
+
|
6
|
+
module Appsules
|
7
|
+
def self.add_factory_bot_paths!
|
8
|
+
Dir[File.join(Appsules.test_path, "*")].each do |appsule_path|
|
9
|
+
FactoryBot.definition_file_paths << File.join(appsule_path, "factories")
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.add_factory_girl_paths!
|
14
|
+
Dir[File.join(Appsules.test_path, "*")].each do |appsule_path|
|
15
|
+
FactoryGirl.definition_file_paths << File.join(appsule_path, "factories")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.test_path
|
20
|
+
return @@test_path if defined?(@@test_path)
|
21
|
+
@@test_path = Rails.root.join("test", "appsules")
|
22
|
+
FileUtils.mkdir_p @@test_path
|
23
|
+
@@test_path
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.path
|
27
|
+
return @@path if defined?(@@path)
|
28
|
+
@@path = Rails.root.join("appsules")
|
29
|
+
FileUtils.mkdir_p @@path
|
30
|
+
@@path
|
31
|
+
end
|
32
|
+
|
33
|
+
# for internal use by the appsules gem
|
34
|
+
def self.add_helpers(appsule_path, initializer_context)
|
35
|
+
return unless initializer_context.respond_to?(:helper)
|
36
|
+
|
37
|
+
helpers_dir = File.join(appsule_path, "helpers")
|
38
|
+
|
39
|
+
Dir[File.join(helpers_dir, "**", "*_helper.rb")].map do |helper_path|
|
40
|
+
module_name = helper_path.sub(%r{^#{helpers_dir}/(.+)\.rb}i, '\1').classify
|
41
|
+
initializer_context.instance_eval "helper #{module_name}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require "pathname"
|
2
|
+
|
3
|
+
module Appsules
|
4
|
+
class Railtie < Rails::Railtie
|
5
|
+
rake_tasks do
|
6
|
+
Dir[File.join(__dir__, "tasks", "*.rake")].each { |f| load f }
|
7
|
+
Dir[File.join(Appsules.path, "*", "tasks", "*.rake")].each { |f| load f }
|
8
|
+
end
|
9
|
+
|
10
|
+
# Add each appsule"s immediate subdirectories as eager_load paths
|
11
|
+
initializer "appsules.autoload", before: :set_autoload_paths do |app|
|
12
|
+
appsule_paths = Dir.glob(File.join(Appsules.path, "*/*/"))
|
13
|
+
app.config.autoload_paths += appsule_paths
|
14
|
+
app.config.eager_load_paths += appsule_paths
|
15
|
+
end
|
16
|
+
|
17
|
+
initializer "appsules.autoload_views" do |app|
|
18
|
+
ActiveSupport.on_load :action_controller do
|
19
|
+
Dir[File.join(Appsules.path, "*")].each do |appsule_path|
|
20
|
+
Appsules.add_helpers(appsule_path, self)
|
21
|
+
append_view_path File.join(appsule_path, "views")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# Add /test/appsules to $LOAD_PATH in the test environment
|
27
|
+
initializer "appsules.tests_load_path" do |app|
|
28
|
+
$LOAD_PATH << Appsules.test_path.to_s if Rails.env.test?
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "rails/test_unit/runner"
|
2
|
+
|
3
|
+
namespace :test do
|
4
|
+
namespace :appsule do
|
5
|
+
Dir[File.join(Appsules.test_path, "*")].each do |appsule_path|
|
6
|
+
appsule_name = appsule_path.split("/").last
|
7
|
+
Rake::Task[:test].enhance { Rake::Task["test:appsule:#{appsule_name}"].invoke }
|
8
|
+
|
9
|
+
desc "run tests for appsule #{appsule_name}"
|
10
|
+
task appsule_name => "test:prepare" do
|
11
|
+
pattern = File.join(appsule_path, "**", "*_test.rb")
|
12
|
+
Rails::TestUnit::Runner.run(Dir.glob(pattern))
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: appsules
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Wyatt Greene
|
8
|
+
- Michael Deutsch
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2018-01-17 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rails
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '5.0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '5.0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
description: Appsules are a different way to organize your Rails app files
|
43
|
+
email:
|
44
|
+
- mdeutsch@patientslikeme.com
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".gitignore"
|
50
|
+
- ".rubocop.yml"
|
51
|
+
- CHANGELOG.md
|
52
|
+
- Gemfile
|
53
|
+
- LICENSE.txt
|
54
|
+
- README.md
|
55
|
+
- Rakefile
|
56
|
+
- appsules.gemspec
|
57
|
+
- lib/appsules.rb
|
58
|
+
- lib/appsules/railtie.rb
|
59
|
+
- lib/appsules/tasks/test.rake
|
60
|
+
- lib/appsules/version.rb
|
61
|
+
homepage: https://github.com/patientslikeme/appsules
|
62
|
+
licenses:
|
63
|
+
- MIT
|
64
|
+
metadata: {}
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
requirements: []
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 2.5.2
|
82
|
+
signing_key:
|
83
|
+
specification_version: 4
|
84
|
+
summary: Appsules are a different way to organize your Rails app files
|
85
|
+
test_files: []
|