super_module 1.2.1 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +20 -17
- data/VERSION +1 -1
- data/super_module.gemspec +6 -6
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 80fcc01874eafdb2bf870cd3e06f55a135d830d1
|
4
|
+
data.tar.gz: 7c9b6e1a8b5f16b19ff60755c2258b3e67da3484
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e0f9ac72e8ae4aaf4fee64d9aaae54a996de85d7e18b3f5de523bef20bc0b1362bca31bc3317888fe1de405468cc43ef117de47098792ffbb98642deb42de3d5
|
7
|
+
data.tar.gz: 9e0dd6a4468c5719a99197a2136c4a9b5078009c2b78aa5fb0feb5674f322b2020648658fa279bd43caad6b68074f32eeb2e2836c23927d61c428dcd4985b9d3
|
data/README.md
CHANGED
@@ -1,12 +1,11 @@
|
|
1
|
-
# <img src="https://raw.githubusercontent.com/AndyObtiva/super_module/master/SuperModule.jpg" alt="SuperModule" align="left" height="50" /> SuperModule 2 Beta
|
1
|
+
# <img src="https://raw.githubusercontent.com/AndyObtiva/super_module/master/SuperModule.jpg" alt="SuperModule" align="left" height="50" /> SuperModule 2 Beta
|
2
2
|
[![Gem Version](https://badge.fury.io/rb/super_module.svg)](http://badge.fury.io/rb/super_module)
|
3
|
-
[![Build Status](https://api.travis-ci.org/AndyObtiva/super_module.svg?branch=master)](https://travis-ci.org/AndyObtiva/super_module)
|
4
3
|
[![Coverage Status](https://coveralls.io/repos/AndyObtiva/super_module/badge.svg?branch=master)](https://coveralls.io/r/AndyObtiva/super_module?branch=master)
|
5
4
|
[![Code Climate](https://codeclimate.com/github/AndyObtiva/super_module.svg)](https://codeclimate.com/github/AndyObtiva/super_module)
|
6
5
|
|
7
|
-
Calling [Ruby](https://www.ruby-lang.org/en/)'s [`Module#include`](http://ruby-doc.org/core-2.2.1/Module.html#method-i-include) to mix in a module does not bring in class methods by default. This can come as quite the surprise when attempting to include class methods via a module.
|
6
|
+
Calling [Ruby](https://www.ruby-lang.org/en/)'s [`Module#include`](http://ruby-doc.org/core-2.2.1/Module.html#method-i-include) to mix in a module does not bring in class methods by default. This can come as quite the surprise when attempting to include class methods via a module.
|
8
7
|
|
9
|
-
Ruby offers one workaround in the form of implementing the hook method [`Module.included(base)`](http://ruby-doc.org/core-2.2.1/Module.html#method-i-included) [following a certain boilerplate code idiom](http://www.railstips.org/blog/archives/2009/05/15/include-vs-extend-in-ruby/). Unfortunately, it hinders code maintainability and productivity with extra unnecessary complexity, especially in production-environment projects employing many [mixins](http://en.wikipedia.org/wiki/Mixin) (e.g. modeling business domain models with composable object [traits](http://en.wikipedia.org/wiki/Trait_(computer_programming))).
|
8
|
+
Ruby offers one workaround in the form of implementing the hook method [`Module.included(base)`](http://ruby-doc.org/core-2.2.1/Module.html#method-i-included) [following a certain boilerplate code idiom](http://www.railstips.org/blog/archives/2009/05/15/include-vs-extend-in-ruby/). Unfortunately, it hinders code maintainability and productivity with extra unnecessary complexity, especially in production-environment projects employing many [mixins](http://en.wikipedia.org/wiki/Mixin) (e.g. modeling business domain models with composable object [traits](http://en.wikipedia.org/wiki/Trait_(computer_programming))).
|
10
9
|
|
11
10
|
Another workaround is [`ActiveSupport::Concern`](http://api.rubyonrails.org/classes/ActiveSupport/Concern.html), a Rails library that attempts to ease some of the boilerplate pain by offering a [DSL](http://www.infoq.com/news/2007/06/dsl-or-not) layer on top of [`Module.included(base)`](http://ruby-doc.org/core-2.2.1/Module.html#method-i-included). Unfortunately, while it helps improve readability a bit, it adds even more boilerplate idiom cruft, thus feeling no more than putting a band-aid on the problem.
|
12
11
|
|
@@ -30,13 +29,13 @@ module UserIdentifiable
|
|
30
29
|
validates :user_id, presence: true
|
31
30
|
end
|
32
31
|
end
|
33
|
-
|
32
|
+
|
34
33
|
module ClassMethods
|
35
34
|
def most_active_user
|
36
35
|
User.find_by_id(select('count(id) as head_count, user_id').group('user_id').order('count(id) desc').first.user_id)
|
37
36
|
end
|
38
37
|
end
|
39
|
-
|
38
|
+
|
40
39
|
def slug
|
41
40
|
"#{self.class.name}_#{user_id}"
|
42
41
|
end
|
@@ -56,13 +55,13 @@ module UserIdentifiable
|
|
56
55
|
belongs_to :user
|
57
56
|
validates :user_id, presence: true
|
58
57
|
end
|
59
|
-
|
58
|
+
|
60
59
|
module ClassMethods
|
61
60
|
def most_active_user
|
62
61
|
User.find_by_id(select('count(id) as head_count, user_id').group('user_id').order('count(id) desc').first.user_id)
|
63
62
|
end
|
64
63
|
end
|
65
|
-
|
64
|
+
|
66
65
|
def slug
|
67
66
|
"#{self.class.name}_#{user_id}"
|
68
67
|
end
|
@@ -76,7 +75,7 @@ A step forward that addresses the boiler-plate repetitive code concern, but is o
|
|
76
75
|
```ruby
|
77
76
|
super_module :UserIdentifiable do
|
78
77
|
include ActiveModel::Model
|
79
|
-
|
78
|
+
|
80
79
|
belongs_to :user
|
81
80
|
validates :user_id, presence: true
|
82
81
|
|
@@ -110,7 +109,7 @@ end
|
|
110
109
|
|
111
110
|
<b>Using [Bundler](http://bundler.io/)</b>
|
112
111
|
|
113
|
-
Add the following to Gemfile: <pre>gem 'super_module', '1.
|
112
|
+
Add the following to Gemfile: <pre>gem 'super_module', '1.2.2'</pre>
|
114
113
|
|
115
114
|
And run the following command: <pre>bundle</pre>
|
116
115
|
|
@@ -204,7 +203,7 @@ super_module :RequiresAttributes do
|
|
204
203
|
def self.required_attributes
|
205
204
|
@required_attributes ||= []
|
206
205
|
end
|
207
|
-
|
206
|
+
|
208
207
|
def requirements_satisfied?
|
209
208
|
!!self.class.required_attributes.reduce(true) { |result, required_attribute| result && send(required_attribute) }
|
210
209
|
end
|
@@ -272,16 +271,16 @@ V2 has a much simpler algorithm than V1 that goes as follows:
|
|
272
271
|
|
273
272
|
* [SuperModule](https://rubygems.org/gems/super_module) has been designed to be used only in the initial code definition of a module (not supporting later re-opening of the module.)
|
274
273
|
|
275
|
-
* Given [SuperModule](https://rubygems.org/gems/super_module)'s implementation relies on `self.included(base)`, if an including super module (or a super module including another super module) must hook into <code>self.included(base)</code> for meta-programming cases that require it, such as conditional `include` statements or method definitions, it would have to alias <code>self.included(base)</code> and then invoke the aliased version in every super module that needs it like in this example:
|
276
|
-
```ruby
|
274
|
+
* Given [SuperModule](https://rubygems.org/gems/super_module)'s implementation relies on `self.included(base)`, if an including super module (or a super module including another super module) must hook into <code>self.included(base)</code> for meta-programming cases that require it, such as conditional `include` statements or method definitions, it would have to alias <code>self.included(base)</code> and then invoke the aliased version in every super module that needs it like in this example:
|
275
|
+
```ruby
|
277
276
|
super_module :AdminIdentifiable do
|
278
277
|
include UserIdentifiable
|
279
|
-
|
278
|
+
|
280
279
|
class << self
|
281
280
|
alias included_super_module included
|
282
281
|
def included(base)
|
283
282
|
included_super_module(base)
|
284
|
-
# do some extra work
|
283
|
+
# do some extra work
|
285
284
|
# like conditional inclusion of other modules
|
286
285
|
# or conditional definition of methods
|
287
286
|
end
|
@@ -292,6 +291,10 @@ In the future, [SuperModule](https://rubygems.org/gems/super_module) could perha
|
|
292
291
|
|
293
292
|
## What's New?
|
294
293
|
|
294
|
+
### v2 Beta (v1.2.2)
|
295
|
+
|
296
|
+
* Relaxed dependency on `method_source` gem version
|
297
|
+
|
295
298
|
### v2 Beta (v1.2.1)
|
296
299
|
|
297
300
|
* Standalone super module usage (e.g. direct class method invocation)
|
@@ -316,11 +319,11 @@ In the future, [SuperModule](https://rubygems.org/gems/super_module) could perha
|
|
316
319
|
* New dependency on [Banister](https://github.com/banister)'s [method_source](https://github.com/banister/method_source) library to have the self-friendly algorithm eval inherited class method sources into the including base class or module.
|
317
320
|
* Refactorings, including break-up of the original SuperModule into 3 modules in separate files
|
318
321
|
* More RSpec test coverage, including additional method definition scenarios, such as when adding dynamically via `class_eval` and `define_method`
|
319
|
-
|
322
|
+
|
320
323
|
## Feedback and Contribution
|
321
324
|
|
322
325
|
[SuperModule](https://rubygems.org/gems/super_module) is written in a very clean and maintainable test-first approach, so you are welcome to read through the code on GitHub for more in-depth details:
|
323
|
-
https://github.com/AndyObtiva/super_module
|
326
|
+
https://github.com/AndyObtiva/super_module
|
324
327
|
|
325
328
|
The library is quite new and can use all the feedback and help it can get. So, please do not hesitate to add comments if you have any, and please fork [the project on GitHub](https://github.com/AndyObtiva/super_module#fork-destination-box) in order to [make contributions via Pull Requests](https://github.com/AndyObtiva/super_module/pulls).
|
326
329
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.2.
|
1
|
+
1.2.2
|
data/super_module.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: super_module 1.2.
|
5
|
+
# stub: super_module 1.2.2 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "super_module".freeze
|
9
|
-
s.version = "1.2.
|
9
|
+
s.version = "1.2.2"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib".freeze]
|
13
13
|
s.authors = ["Andy Maleh".freeze]
|
14
|
-
s.date = "
|
14
|
+
s.date = "2019-08-06"
|
15
15
|
s.description = "SuperModule allows defining class methods and method invocations the same way a super class does without using def included(base). This also succeeds ActiveSupport::Concern by offering lighter syntax".freeze
|
16
16
|
s.extra_rdoc_files = [
|
17
17
|
"LICENSE.txt",
|
@@ -61,7 +61,7 @@ Gem::Specification.new do |s|
|
|
61
61
|
s.specification_version = 4
|
62
62
|
|
63
63
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
64
|
-
s.add_runtime_dependency(%q<method_source>.freeze, ["
|
64
|
+
s.add_runtime_dependency(%q<method_source>.freeze, [">= 0.8.2"])
|
65
65
|
s.add_development_dependency(%q<jeweler>.freeze, ["~> 2.3.0"])
|
66
66
|
s.add_development_dependency(%q<rdoc>.freeze, ["~> 4.2.0"])
|
67
67
|
s.add_development_dependency(%q<rspec>.freeze, ["~> 3.2.0"])
|
@@ -71,7 +71,7 @@ Gem::Specification.new do |s|
|
|
71
71
|
s.add_development_dependency(%q<tins>.freeze, ["~> 1.6.0"])
|
72
72
|
s.add_development_dependency(%q<term-ansicolor>.freeze, ["~> 1.3.2"])
|
73
73
|
else
|
74
|
-
s.add_dependency(%q<method_source>.freeze, ["
|
74
|
+
s.add_dependency(%q<method_source>.freeze, [">= 0.8.2"])
|
75
75
|
s.add_dependency(%q<jeweler>.freeze, ["~> 2.3.0"])
|
76
76
|
s.add_dependency(%q<rdoc>.freeze, ["~> 4.2.0"])
|
77
77
|
s.add_dependency(%q<rspec>.freeze, ["~> 3.2.0"])
|
@@ -82,7 +82,7 @@ Gem::Specification.new do |s|
|
|
82
82
|
s.add_dependency(%q<term-ansicolor>.freeze, ["~> 1.3.2"])
|
83
83
|
end
|
84
84
|
else
|
85
|
-
s.add_dependency(%q<method_source>.freeze, ["
|
85
|
+
s.add_dependency(%q<method_source>.freeze, [">= 0.8.2"])
|
86
86
|
s.add_dependency(%q<jeweler>.freeze, ["~> 2.3.0"])
|
87
87
|
s.add_dependency(%q<rdoc>.freeze, ["~> 4.2.0"])
|
88
88
|
s.add_dependency(%q<rspec>.freeze, ["~> 3.2.0"])
|
metadata
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: super_module
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Maleh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-08-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: method_source
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 0.8.2
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 0.8.2
|
27
27
|
- !ruby/object:Gem::Dependency
|