namespaced_mixin 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +75 -0
- data/Rakefile +2 -0
- data/lib/namespaced_mixin.rb +22 -0
- data/lib/namespaced_mixin/version.rb +3 -0
- data/namespaced_mixin.gemspec +24 -0
- data/spec/spec_helper.rb +2 -0
- metadata +97 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d8a9853eab867a3c1c137c402cde44a40fb8f1f4
|
4
|
+
data.tar.gz: 9192145c709f03e0051d69740a270a2d8216be83
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 567fe5aa8c537bec4173919c70ff1a594e8732ff91c5c1a4dea74cc5662dae223b2bd5d53c7e45fbbc05aac7dd2775ad0563761b600e91f31ed8a2cdadaf1b89
|
7
|
+
data.tar.gz: 49c5cf6a23a4d474ca20e695f52ae901c3e91cfc941cd6c676d09eb3af95413dd81292a003500922ce98e2753045381f7629f8bf7f9f573fafaccf31bf6366ec
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Filippos Vasilakis
|
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,75 @@
|
|
1
|
+
# NamespacedMixin
|
2
|
+
|
3
|
+
Namespace your mixins. Proper Composition.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'namespaced_mixin'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install namespaced_mixin
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
You can do such amazing things:
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
require 'namespaced_mixin'
|
26
|
+
|
27
|
+
module TestModule
|
28
|
+
module NestedModule
|
29
|
+
def do_that
|
30
|
+
puts 'Do this'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
module TestModule1
|
36
|
+
def do_that
|
37
|
+
puts 'Doing that'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
module TestModule2
|
42
|
+
def do_that
|
43
|
+
puts 'Do something else'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
class Example
|
48
|
+
include NamespacedMixin
|
49
|
+
|
50
|
+
namespace 'TestModule1', as: :simply
|
51
|
+
namespace 'TestModule2', as: :namespaced
|
52
|
+
namespace 'TestModule::NestedModule', as: :mixins
|
53
|
+
|
54
|
+
include AmazingModule
|
55
|
+
|
56
|
+
#rest of the code
|
57
|
+
|
58
|
+
def stupid_method
|
59
|
+
if simply.do_that == mixins.do_that
|
60
|
+
namespaced.do_that #do something else
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
```
|
65
|
+
|
66
|
+
Usually the methods of the mixins that you want to use should not keep state (act like traits),
|
67
|
+
and support DI.
|
68
|
+
|
69
|
+
## Contributing
|
70
|
+
|
71
|
+
1. Fork it ( https://github.com/[my-github-username]/namespaced_mixin/fork )
|
72
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
73
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
74
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
75
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require "namespaced_mixin/version"
|
2
|
+
|
3
|
+
module NamespacedMixin
|
4
|
+
module ClassMethods
|
5
|
+
def namespace(name, as:)
|
6
|
+
namespace = as.to_s
|
7
|
+
|
8
|
+
namespaced_class = name.to_s.split('::').inject(Object) {|o,c| o.const_get c}
|
9
|
+
cls = Class.new{
|
10
|
+
include namespaced_class
|
11
|
+
}.new
|
12
|
+
|
13
|
+
define_method("#{namespace}") do
|
14
|
+
cls
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.included(base)
|
20
|
+
base.extend(ClassMethods)
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'namespaced_mixin/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "namespaced_mixin"
|
8
|
+
spec.version = NamespacedMixin::VERSION
|
9
|
+
spec.authors = ["Filippos Vasilakis"]
|
10
|
+
spec.email = ["vasilakisfil@gmail.com"]
|
11
|
+
spec.summary = %q{Namespace your mixins in your classes.}
|
12
|
+
spec.description = %q{}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "rspec", "~> 3.1.0"
|
24
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: namespaced_mixin
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Filippos Vasilakis
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-02-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.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: 3.1.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.1.0
|
55
|
+
description: ''
|
56
|
+
email:
|
57
|
+
- vasilakisfil@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- lib/namespaced_mixin.rb
|
69
|
+
- lib/namespaced_mixin/version.rb
|
70
|
+
- namespaced_mixin.gemspec
|
71
|
+
- spec/spec_helper.rb
|
72
|
+
homepage: ''
|
73
|
+
licenses:
|
74
|
+
- MIT
|
75
|
+
metadata: {}
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirements: []
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 2.4.5
|
93
|
+
signing_key:
|
94
|
+
specification_version: 4
|
95
|
+
summary: Namespace your mixins in your classes.
|
96
|
+
test_files:
|
97
|
+
- spec/spec_helper.rb
|