name_space 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +1 -1
- data/README.md +157 -151
- data/lib/namespace/version.rb +1 -1
- data/namespace.gemspec +5 -4
- data/spec/namespace_spec.rb +2 -2
- metadata +22 -20
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b87b16051da3ef6fc303bf4a167f34a7310021be1126a5341acce3073bfbb6f8
|
4
|
+
data.tar.gz: 9a7eef35be0b1f3e01cb310a92deee1a343d22bd0fdcebde0999589c43a0e8db
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: '09d323369968ead503e81b5a6b99f03b0050bb51e4642421963a267969a5dead86635363cf1bfedb381535eb1dad1bb4384bfe1990e1519342be082f5a6d0581'
|
7
|
+
data.tar.gz: f8783cd5b700add3521810e0950295af14e1955126486c114862f1980fce4578f887a9ec20ef171576d6f5e5aacea8da90b117aaf05e01d3c6ade8c487afbeb9
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,151 +1,157 @@
|
|
1
|
-
# Namespace
|
2
|
-
|
3
|
-
Include and Extend your class with Namespace.
|
4
|
-
Method with the same name in different namespaces.
|
5
|
-
|
6
|
-
## Installation
|
7
|
-
|
8
|
-
Add this line to your application's Gemfile:
|
9
|
-
|
10
|
-
gem '
|
11
|
-
|
12
|
-
And then execute:
|
13
|
-
|
14
|
-
$ bundle
|
15
|
-
|
16
|
-
Or install it yourself as:
|
17
|
-
|
18
|
-
$ gem install
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
end
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
namespace :a do
|
119
|
-
def
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
SubSomeClass
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
1
|
+
# Namespace
|
2
|
+
|
3
|
+
Include and Extend your class with Namespace.
|
4
|
+
Method with the same name in different namespaces.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
```ruby
|
10
|
+
gem 'name_space'
|
11
|
+
```
|
12
|
+
And then execute:
|
13
|
+
```ruby
|
14
|
+
$ bundle
|
15
|
+
```
|
16
|
+
Or install it yourself as:
|
17
|
+
```ruby
|
18
|
+
$ gem install name_space
|
19
|
+
```
|
20
|
+
Require gem:
|
21
|
+
```ruby
|
22
|
+
require 'namespace'
|
23
|
+
```
|
24
|
+
|
25
|
+
|
26
|
+
# Usage
|
27
|
+
|
28
|
+
## Define namespace with methods.
|
29
|
+
|
30
|
+
* name - [Symbol] - namespace name,
|
31
|
+
|
32
|
+
* block - [Block] with methods
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
class SomeClass
|
36
|
+
include Namespace
|
37
|
+
extend Namespace
|
38
|
+
|
39
|
+
namespace :my_namespace do
|
40
|
+
def method_a
|
41
|
+
'method_a'
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# For Instance
|
47
|
+
SomeClass.new.my_namespace.method_a # => 'method_a'
|
48
|
+
# For class
|
49
|
+
SomeClass.my_namespace.method_a # => 'method_a'
|
50
|
+
```
|
51
|
+
## Outer methods
|
52
|
+
|
53
|
+
All *namespaces* can call outer methods.
|
54
|
+
```ruby
|
55
|
+
class SomeClass
|
56
|
+
include Namespace
|
57
|
+
extend Namespace
|
58
|
+
|
59
|
+
def outer
|
60
|
+
'outer'
|
61
|
+
end
|
62
|
+
|
63
|
+
namespace :my_namespace do
|
64
|
+
def method_a
|
65
|
+
outer
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
SomeClass.new.my_namespace.method_a #=> outer
|
71
|
+
```
|
72
|
+
|
73
|
+
## Get all namespaces for class with `namespaces` method
|
74
|
+
```ruby
|
75
|
+
class SomeClass
|
76
|
+
include Namespace
|
77
|
+
extend Namespace
|
78
|
+
|
79
|
+
namespace :a do
|
80
|
+
end
|
81
|
+
namespace :b do
|
82
|
+
end
|
83
|
+
namespace :c do
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
SomeClass.new.namespaces # => [:a, :b, :c]
|
88
|
+
```
|
89
|
+
|
90
|
+
## Reopen namespace.
|
91
|
+
|
92
|
+
You can reopen any namespace
|
93
|
+
```ruby
|
94
|
+
class SomeClass
|
95
|
+
include Namespace
|
96
|
+
extend Namespace
|
97
|
+
|
98
|
+
namespace :a do
|
99
|
+
def a; 'a' end
|
100
|
+
end
|
101
|
+
namespace :a do
|
102
|
+
def b; 'b' end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
SomeClass.a.a # => 'a'
|
107
|
+
SomeClass.a.b # => 'b'
|
108
|
+
```
|
109
|
+
|
110
|
+
##Namespaces and Inheritance.
|
111
|
+
|
112
|
+
All namespaces from superclass available in subclasses.
|
113
|
+
```ruby
|
114
|
+
class SomeClass
|
115
|
+
include Namespace
|
116
|
+
extend Namespace
|
117
|
+
|
118
|
+
namespace :a do
|
119
|
+
def a; 'super' end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
class SubSomeClass < SomeClass
|
124
|
+
namespace :a do
|
125
|
+
def 'a'; 'subclass' end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
SubSomeClass.a.a # => 'subclass'
|
130
|
+
```
|
131
|
+
|
132
|
+
##Namespaces with Rails.
|
133
|
+
|
134
|
+
It can be use for save scopes (for example).
|
135
|
+
```ruby
|
136
|
+
class Model < AR::B
|
137
|
+
include Namespace
|
138
|
+
extend Namespace
|
139
|
+
|
140
|
+
scope :lasts, ->{ }
|
141
|
+
namespace :my_custom_scopes do
|
142
|
+
scope :lasts, ->{ }
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
Model.lasts # => return from "lasts" scope
|
147
|
+
Model.my_custom_scopes.lasts # => return from namespace scope, "lasts" scope will be override
|
148
|
+
```
|
149
|
+
|
150
|
+
|
151
|
+
## Contributing
|
152
|
+
|
153
|
+
1. Fork it
|
154
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
155
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
156
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
157
|
+
5. Create new Pull Request
|
data/lib/namespace/version.rb
CHANGED
data/namespace.gemspec
CHANGED
@@ -6,15 +6,16 @@ require 'namespace/version'
|
|
6
6
|
Gem::Specification.new do |gem|
|
7
7
|
gem.name = "name_space"
|
8
8
|
gem.version = Namespace::VERSION
|
9
|
-
gem.authors = ["
|
10
|
-
gem.email = ["
|
9
|
+
gem.authors = ["fntz"]
|
10
|
+
gem.email = ["mike.fch1@gmail.com"]
|
11
11
|
gem.description = "Add Namespace functionality"
|
12
12
|
gem.summary = "Include and Extend your class with Namespace. Create methods with the same name in different namespaces."
|
13
|
-
gem.homepage =
|
13
|
+
gem.homepage = 'https://github.com/fntz/namespace'
|
14
|
+
gem.license = 'MIT'
|
14
15
|
|
15
16
|
gem.files = `git ls-files`.split($/)
|
16
17
|
gem.test_files = gem.files.grep(%r{^(spec|spec|features)/})
|
17
18
|
gem.require_paths = ["lib"]
|
18
19
|
|
19
|
-
gem.add_development_dependency
|
20
|
+
gem.add_development_dependency 'rspec', '~> 2.0', '>= 2.0.0'
|
20
21
|
end
|
data/spec/namespace_spec.rb
CHANGED
@@ -130,9 +130,9 @@ describe Namespace do
|
|
130
130
|
end
|
131
131
|
|
132
132
|
it "return all method from namespace" do
|
133
|
-
D.a.nmethods.should
|
133
|
+
D.a.nmethods.should =~ [:a, :b, :c]
|
134
134
|
D.b.nmethods.should eq [:a]
|
135
|
-
D.new.a.nmethods.should
|
135
|
+
D.new.a.nmethods.should =~ [:a, :b, :c]
|
136
136
|
D.new.b.nmethods.should eq [:a]
|
137
137
|
end
|
138
138
|
end
|
metadata
CHANGED
@@ -1,41 +1,44 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: name_space
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
|
-
-
|
7
|
+
- fntz
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2018-11-24 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rspec
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
- - ">="
|
20
21
|
- !ruby/object:Gem::Version
|
21
22
|
version: 2.0.0
|
22
23
|
type: :development
|
23
24
|
prerelease: false
|
24
25
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
26
|
requirements:
|
27
|
-
- -
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '2.0'
|
30
|
+
- - ">="
|
28
31
|
- !ruby/object:Gem::Version
|
29
32
|
version: 2.0.0
|
30
33
|
description: Add Namespace functionality
|
31
34
|
email:
|
32
|
-
-
|
35
|
+
- mike.fch1@gmail.com
|
33
36
|
executables: []
|
34
37
|
extensions: []
|
35
38
|
extra_rdoc_files: []
|
36
39
|
files:
|
37
|
-
- .gitignore
|
38
|
-
- .rspec
|
40
|
+
- ".gitignore"
|
41
|
+
- ".rspec"
|
39
42
|
- Gemfile
|
40
43
|
- LICENSE.txt
|
41
44
|
- README.md
|
@@ -47,32 +50,31 @@ files:
|
|
47
50
|
- namespace.gemspec
|
48
51
|
- spec/namespace_spec.rb
|
49
52
|
- spec/spec_helper.rb
|
50
|
-
homepage: https://github.com/
|
51
|
-
licenses:
|
53
|
+
homepage: https://github.com/fntz/namespace
|
54
|
+
licenses:
|
55
|
+
- MIT
|
56
|
+
metadata: {}
|
52
57
|
post_install_message:
|
53
58
|
rdoc_options: []
|
54
59
|
require_paths:
|
55
60
|
- lib
|
56
61
|
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
62
|
requirements:
|
59
|
-
- -
|
63
|
+
- - ">="
|
60
64
|
- !ruby/object:Gem::Version
|
61
65
|
version: '0'
|
62
66
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
-
none: false
|
64
67
|
requirements:
|
65
|
-
- -
|
68
|
+
- - ">="
|
66
69
|
- !ruby/object:Gem::Version
|
67
70
|
version: '0'
|
68
71
|
requirements: []
|
69
72
|
rubyforge_project:
|
70
|
-
rubygems_version:
|
73
|
+
rubygems_version: 2.7.6
|
71
74
|
signing_key:
|
72
|
-
specification_version:
|
75
|
+
specification_version: 4
|
73
76
|
summary: Include and Extend your class with Namespace. Create methods with the same
|
74
77
|
name in different namespaces.
|
75
78
|
test_files:
|
76
79
|
- spec/namespace_spec.rb
|
77
80
|
- spec/spec_helper.rb
|
78
|
-
has_rdoc:
|