rails_module_unification 0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +55 -0
- data/lib/rails_module_unification.rb +11 -0
- data/lib/rails_module_unification/active_support_extensions.rb +104 -0
- data/lib/rails_module_unification/railtie.rb +21 -0
- data/lib/rails_module_unification/version.rb +4 -0
- metadata +217 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d534fbc4e2d179f5c74b7a474a39e3bdf44af115
|
4
|
+
data.tar.gz: 1582f310105cd5e2e412522252d94a275480b579
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7862c364eb26de506fc4be7216960636310a81c5b66e9d4d1686f05d506531d1b68e597bd6d9599c07ba1111c42252426e1c35198f9203353ea7a55ee232aff0
|
7
|
+
data.tar.gz: 0309ad0ddffd8e1db286713b538f5db999eac112d4530816a790ba1ebe84ddb8d22f4c93e8f6ac240519ce6391c1d541deb6c4c62e773685dfc3778b5e6e89fd
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2016 L. Preston Sego III
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# rails_module_unification
|
2
|
+
Ember's module unification brought to Rails.
|
3
|
+
|
4
|
+
## What is this about?
|
5
|
+
|
6
|
+
With large rails application, the default architecture can result in a resource's related files being very spread out through the overall project structure. For example, lets say you have 50 controllers, serializers, policies, and operations. That's _four_ different top level folders that spread out all the related objects. It makes sense do it this way, as it makes rails' autoloading programmatically easy.
|
7
|
+
|
8
|
+
This gem provides a way to re-structure your app so that like-objects are grouped together.
|
9
|
+
|
10
|
+
### The new structure
|
11
|
+
|
12
|
+
|
13
|
+
```
|
14
|
+
app/
|
15
|
+
├── channels/
|
16
|
+
├── data/
|
17
|
+
│ └── models/
|
18
|
+
│ ├── post.rb
|
19
|
+
│ ├── comment.rb
|
20
|
+
├── jobs/
|
21
|
+
├── mailers/
|
22
|
+
│ └── notification_mailer.rb
|
23
|
+
└── resources/
|
24
|
+
├── posts/
|
25
|
+
│ ├── controller.rb
|
26
|
+
│ ├── operation.rb
|
27
|
+
│ ├── policy.rb
|
28
|
+
│ └── serializer.rb
|
29
|
+
└── comments/
|
30
|
+
├── controller.rb
|
31
|
+
└── serializer.rb
|
32
|
+
|
33
|
+
```
|
34
|
+
|
35
|
+
## Usage
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
gem 'rails_module_unification'
|
39
|
+
```
|
40
|
+
|
41
|
+
Including the gem in your gemfile enables the new structure.
|
42
|
+
|
43
|
+
## Configuration
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
RailsModuleUnification.directory = 'pods'
|
47
|
+
```
|
48
|
+
|
49
|
+
Sets the folder for the new structure to be in the `app/pods` directory so that you can gradually migrate to the new structure over time.
|
50
|
+
|
51
|
+
## Contributing
|
52
|
+
|
53
|
+
Feel free to open an issue, or fork and make a pull request.
|
54
|
+
|
55
|
+
All discussion is welcome :-)
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support'
|
4
|
+
require 'rails_module_unification/active_support_extensions'
|
5
|
+
|
6
|
+
module RailsModuleUnification
|
7
|
+
extend ActiveSupport::Autoload
|
8
|
+
|
9
|
+
require 'rails_module_unification/railtie'
|
10
|
+
ActiveSupport::Dependencies.extend ActiveSupportExtensions
|
11
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
module RailsModuleUnification
|
2
|
+
module ActiveSupportExtensions
|
3
|
+
def load_from_path(file_path, qualified_name, from_mod, const_name)
|
4
|
+
expanded = File.expand_path(file_path)
|
5
|
+
expanded.sub!(/\.rb\z/, ''.freeze)
|
6
|
+
|
7
|
+
if loading.include?(expanded)
|
8
|
+
raise "Circular dependency detected while autoloading constant #{qualified_name}"
|
9
|
+
else
|
10
|
+
require_or_load(expanded, qualified_name)
|
11
|
+
raise LoadError, "Unable to autoload constant #{qualified_name}, expected #{file_path} to define it" unless from_mod.const_defined?(const_name, false)
|
12
|
+
return from_mod.const_get(const_name)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# Load the constant named +const_name+ which is missing from +from_mod+. If
|
17
|
+
# it is not possible to load the constant into from_mod, try its parent
|
18
|
+
# module using +const_missing+.
|
19
|
+
def load_missing_constant(from_mod, const_name)
|
20
|
+
# always default to the actual implementation
|
21
|
+
super
|
22
|
+
rescue LoadError, NameError
|
23
|
+
suffixes = /(Controller|Serializer)\z/
|
24
|
+
|
25
|
+
# examples
|
26
|
+
# - Api::PostsController
|
27
|
+
# - PostsController
|
28
|
+
qualified_name = qualified_name_for from_mod, const_name
|
29
|
+
|
30
|
+
# examples
|
31
|
+
# - api/posts_controller
|
32
|
+
# - posts_controller
|
33
|
+
file_name = qualified_name.underscore.split('/').last
|
34
|
+
|
35
|
+
# examples
|
36
|
+
# - controller
|
37
|
+
# - serializer
|
38
|
+
type_name = file_name.split('_').last
|
39
|
+
|
40
|
+
# folder/named_type.rb
|
41
|
+
# examples:
|
42
|
+
# - api/posts
|
43
|
+
# - posts
|
44
|
+
folder_name = qualified_name.split(suffixes).first.underscore.pluralize
|
45
|
+
|
46
|
+
# examples:
|
47
|
+
# - posts/posts_controller
|
48
|
+
folder_named_type = folder_name + '/' + file_name
|
49
|
+
|
50
|
+
# folder/type.rb
|
51
|
+
folder_type_name = folder_name + '/' + type_name
|
52
|
+
|
53
|
+
|
54
|
+
# without a folder / namespace?
|
55
|
+
# TODO: could this have undesired consequences?
|
56
|
+
file_path = search_for_file(file_name)
|
57
|
+
# the resource_name/controller.rb naming scheme
|
58
|
+
file_path ||= search_for_file(folder_type_name)
|
59
|
+
# the resource_name/resource_names_controller.rb naming scheme
|
60
|
+
file_path ||= search_for_file(folder_named_type)
|
61
|
+
|
62
|
+
return load_from_path(file_path, qualified_name, from_mod, const_name) if file_path
|
63
|
+
|
64
|
+
|
65
|
+
if mod = autoload_module!(from_mod, const_name, qualified_name, file_name)
|
66
|
+
return mod
|
67
|
+
elsif (parent = from_mod.parent) && parent != from_mod &&
|
68
|
+
! from_mod.parents.any? { |p| p.const_defined?(const_name, false) }
|
69
|
+
# If our parents do not have a constant named +const_name+ then we are free
|
70
|
+
# to attempt to load upwards. If they do have such a constant, then this
|
71
|
+
# const_missing must be due to from_mod::const_name, which should not
|
72
|
+
# return constants from from_mod's parents.
|
73
|
+
begin
|
74
|
+
# Since Ruby does not pass the nesting at the point the unknown
|
75
|
+
# constant triggered the callback we cannot fully emulate constant
|
76
|
+
# name lookup and need to make a trade-off: we are going to assume
|
77
|
+
# that the nesting in the body of Foo::Bar is [Foo::Bar, Foo] even
|
78
|
+
# though it might not be. Counterexamples are
|
79
|
+
#
|
80
|
+
# class Foo::Bar
|
81
|
+
# Module.nesting # => [Foo::Bar]
|
82
|
+
# end
|
83
|
+
#
|
84
|
+
# or
|
85
|
+
#
|
86
|
+
# module M::N
|
87
|
+
# module S::T
|
88
|
+
# Module.nesting # => [S::T, M::N]
|
89
|
+
# end
|
90
|
+
# end
|
91
|
+
#
|
92
|
+
# for example.
|
93
|
+
return parent.const_missing(const_name)
|
94
|
+
rescue NameError => e
|
95
|
+
raise unless e.missing_name? qualified_name_for(parent, const_name)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
name_error = NameError.new("uninitialized constant #{qualified_name}", const_name)
|
100
|
+
name_error.set_backtrace(caller.reject {|l| l.starts_with? __FILE__ })
|
101
|
+
raise name_error
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'rails/railtie'
|
3
|
+
|
4
|
+
module RailsModuleUnification
|
5
|
+
class Railtie < Rails::Railtie
|
6
|
+
initializer 'activeservice.autoload', before: :set_autoload_paths do |app|
|
7
|
+
# TODO: make the module unification root directory configurable
|
8
|
+
mu_dir = "#{Rails.root}/app/mu"
|
9
|
+
|
10
|
+
# Data
|
11
|
+
data_paths = Dir["#{mu_dir}/data/**/"]
|
12
|
+
ap data_paths
|
13
|
+
app.config.autoload_paths += data_paths
|
14
|
+
|
15
|
+
# Resources
|
16
|
+
resource_paths = Dir["#{mu_dir}/resources/"]
|
17
|
+
ap resource_paths
|
18
|
+
app.config.autoload_paths += resource_paths
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,217 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails_module_unification
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.5'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- L. Preston Sego III
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-09-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rubocop
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: codeclimate-test-reporter
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: awesome_print
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry-byebug
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: bundler
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rails
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: factory_girl
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: factory_girl_rails
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: rspec-rails
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: sqlite3
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
|
+
description: Ember's Module Unification brought to Rails
|
182
|
+
email: LPSego3+dev@gmail.com
|
183
|
+
executables: []
|
184
|
+
extensions: []
|
185
|
+
extra_rdoc_files: []
|
186
|
+
files:
|
187
|
+
- LICENSE
|
188
|
+
- README.md
|
189
|
+
- lib/rails_module_unification.rb
|
190
|
+
- lib/rails_module_unification/active_support_extensions.rb
|
191
|
+
- lib/rails_module_unification/railtie.rb
|
192
|
+
- lib/rails_module_unification/version.rb
|
193
|
+
homepage: https://github.com/NullVoxPopuli/rails_module_unification
|
194
|
+
licenses:
|
195
|
+
- MIT
|
196
|
+
metadata: {}
|
197
|
+
post_install_message:
|
198
|
+
rdoc_options: []
|
199
|
+
require_paths:
|
200
|
+
- lib
|
201
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
202
|
+
requirements:
|
203
|
+
- - ">="
|
204
|
+
- !ruby/object:Gem::Version
|
205
|
+
version: '2.0'
|
206
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
207
|
+
requirements:
|
208
|
+
- - ">="
|
209
|
+
- !ruby/object:Gem::Version
|
210
|
+
version: '0'
|
211
|
+
requirements: []
|
212
|
+
rubyforge_project:
|
213
|
+
rubygems_version: 2.5.1
|
214
|
+
signing_key:
|
215
|
+
specification_version: 4
|
216
|
+
summary: RailsModuleUnification-0.5
|
217
|
+
test_files: []
|