module_plus 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/.gitignore +13 -0
- data/.rspec +2 -0
- data/.rubocop.yml +29 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +59 -0
- data/Rakefile +7 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/module_plus.rb +8 -0
- data/lib/module_plus/attribute.rb +34 -0
- data/lib/module_plus/config_convention.rb +184 -0
- data/lib/module_plus/core_ext/hash.rb +36 -0
- data/lib/module_plus/core_ext/string.rb +39 -0
- data/lib/module_plus/exception.rb +14 -0
- data/lib/module_plus/identification.rb +53 -0
- data/lib/module_plus/version.rb +5 -0
- data/module_plus.gemspec +30 -0
- metadata +134 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: fad1d024e316d40aad5060a1a5de28cde52a3e6e85ac1ca0e64e647f831500e7
|
4
|
+
data.tar.gz: 1b0574c60e2b7881dbda1f73010b0b0d875996e0e6ed466796d9f97a18976237
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 82344567f0ab7e3dfbba818d364ca67de5b5285c5c535e3938e839504c9d18e7ea36ea7bb3f011fa0d57b3d51b1f621a4d5160e52e0eea8d3afd2616f9611bbd
|
7
|
+
data.tar.gz: bde7f908ab24f92cb0c1d80f9bb71633a33add66a02e0898fa0c459ae3dde16a824f5309c72d47fa4a553315cd2c944c566170c48e99f0fa5db553a4c3b98383
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
|
2
|
+
AllCops:
|
3
|
+
Include:
|
4
|
+
- 'Gemfile'
|
5
|
+
Exclude:
|
6
|
+
- 'bin/**/*'
|
7
|
+
- 'vender/**/*'
|
8
|
+
- 'spec/**/*'
|
9
|
+
|
10
|
+
FileName:
|
11
|
+
Exclude:
|
12
|
+
- '**/Rakefile'
|
13
|
+
- '**/Gemfile'
|
14
|
+
|
15
|
+
# Use UTF-8 as the source file encoding.
|
16
|
+
Encoding:
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
#
|
20
|
+
Style/FrozenStringLiteralComment:
|
21
|
+
Enabled: false
|
22
|
+
|
23
|
+
#
|
24
|
+
Style/Documentation:
|
25
|
+
Enabled: false
|
26
|
+
|
27
|
+
#
|
28
|
+
Style/RedundantSelf:
|
29
|
+
Enabled: false
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at satoyama@linkode.co.jp. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 satoyama
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# ModulePlus
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/module_plus`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'module_plus'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install module_plus
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
ModulePlus prevent you mistaking usage of module with 'extend/include'.
|
26
|
+
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
require 'module_plus'
|
30
|
+
|
31
|
+
module M
|
32
|
+
extend ExtendOnly
|
33
|
+
end
|
34
|
+
|
35
|
+
class S
|
36
|
+
extend M
|
37
|
+
end
|
38
|
+
|
39
|
+
class E
|
40
|
+
include ExtendOnly
|
41
|
+
end
|
42
|
+
```
|
43
|
+
|
44
|
+
|
45
|
+
## Development
|
46
|
+
|
47
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
48
|
+
|
49
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
50
|
+
|
51
|
+
## Contributing
|
52
|
+
|
53
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/module_plus. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
54
|
+
|
55
|
+
|
56
|
+
## License
|
57
|
+
|
58
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
59
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "module_plus"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/module_plus.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
#-*- mode: ruby; coding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'module_plus/exception'
|
4
|
+
|
5
|
+
module ModulePlus
|
6
|
+
module Attribute
|
7
|
+
include ModulePlus::Exception
|
8
|
+
module ExtendGuard
|
9
|
+
def extended(klass)
|
10
|
+
raise NotPermittedToExtend, "#{self.name} by #{klass}"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
module IncludeGuard
|
15
|
+
def included(klass)
|
16
|
+
raise NotPermittedToInclude, "#{self.name} by #{klass}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
module ExtendOnly
|
21
|
+
extend IncludeGuard
|
22
|
+
def self.extended(klass)
|
23
|
+
klass.extend(IncludeGuard)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
module IncludeOnly
|
28
|
+
extend ExtendGuard
|
29
|
+
def self.included(klass)
|
30
|
+
klass.extend(ExtendGuard)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,184 @@
|
|
1
|
+
# -*-mode: ruby; coding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'module_plus/attribute'
|
4
|
+
require 'module_plus/identification'
|
5
|
+
require 'module_plus/core_ext/string'
|
6
|
+
require 'module_plus/core_ext/hash'
|
7
|
+
|
8
|
+
require 'ostruct'
|
9
|
+
require 'pathname'
|
10
|
+
require 'yaml'
|
11
|
+
|
12
|
+
|
13
|
+
module ModulePlus
|
14
|
+
|
15
|
+
module ConfigConvention
|
16
|
+
include ModulePlus::Attribute
|
17
|
+
extend ExtendOnly
|
18
|
+
|
19
|
+
class << self
|
20
|
+
def extended(klass)
|
21
|
+
super
|
22
|
+
klass.extend(ModulePlus::Identification)
|
23
|
+
end
|
24
|
+
|
25
|
+
attr_reader :config_hash
|
26
|
+
|
27
|
+
def add_def(c)
|
28
|
+
array = (c.path << c.key.to_s).reverse
|
29
|
+
h = array.inject(c.sample){ |h, k| {k => h}}
|
30
|
+
@config_hash ||= Hash.new { |h,k| h[k] = Hash.new(&h.default_proc) }
|
31
|
+
@config_hash.deep_merge!( h )
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
def field_path_position_top
|
36
|
+
@field_path_position ||= 0
|
37
|
+
end
|
38
|
+
|
39
|
+
def field_path_position_no_head
|
40
|
+
@field_path_position ||= 1
|
41
|
+
end
|
42
|
+
|
43
|
+
def field_path(array)
|
44
|
+
field_path_position_no_head
|
45
|
+
array.drop(@field_path_position)
|
46
|
+
end
|
47
|
+
|
48
|
+
def config_file=(f)
|
49
|
+
@config_file ||= f
|
50
|
+
end
|
51
|
+
|
52
|
+
def config_file
|
53
|
+
@config_file || 'config.yml'
|
54
|
+
end
|
55
|
+
|
56
|
+
def root_dir=(d)
|
57
|
+
@config_root = d
|
58
|
+
end
|
59
|
+
|
60
|
+
def root_dir
|
61
|
+
@config_root || ENV['HOME']
|
62
|
+
end
|
63
|
+
|
64
|
+
def config_dir=(d)
|
65
|
+
@config_dir ||= d
|
66
|
+
end
|
67
|
+
|
68
|
+
def config_dir
|
69
|
+
@config_dir
|
70
|
+
end
|
71
|
+
|
72
|
+
def dump(fs)
|
73
|
+
YAML.dump(@config_hash, fs)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def config
|
78
|
+
@_config ||= config_load
|
79
|
+
end
|
80
|
+
|
81
|
+
#
|
82
|
+
|
83
|
+
def config_dir
|
84
|
+
Pathname.new(ConfigConvention.root_dir)
|
85
|
+
.join(ConfigConvention.config_dir || '.' + root_name.underscore)
|
86
|
+
end
|
87
|
+
|
88
|
+
def config_file
|
89
|
+
config_dir.join(ConfigConvention.config_file)
|
90
|
+
end
|
91
|
+
|
92
|
+
protected
|
93
|
+
|
94
|
+
def config_def(key, attributes = {} )
|
95
|
+
@config_defs ||= {}
|
96
|
+
c = ConfigDef.new(key, field_path, attributes)
|
97
|
+
@config_defs[c.key] = c
|
98
|
+
ConfigConvention.add_def(c)
|
99
|
+
end
|
100
|
+
|
101
|
+
attr_reader :config_defs
|
102
|
+
|
103
|
+
|
104
|
+
private
|
105
|
+
def config_load
|
106
|
+
if config_file.exist? and yaml = YAML.load_file(config_file)
|
107
|
+
c = field_path.inject(yaml) do |h, k|
|
108
|
+
if h[k].is_a? Hash
|
109
|
+
h[k]
|
110
|
+
else
|
111
|
+
raise NotFoundField.new( "Not Found Field #{k} in #{config_file}")
|
112
|
+
end
|
113
|
+
end
|
114
|
+
diff = @config_defs.keys - c.keys
|
115
|
+
raise NotFoundField.new( "Field Key: #{diff.join(", ")} in #{} #{config_file}") unless diff.empty?
|
116
|
+
@config_defs.values.each do |d|
|
117
|
+
c[d.key] = d.value(c[d.key])
|
118
|
+
end
|
119
|
+
ost = OpenStruct.new(c)
|
120
|
+
ost.freeze
|
121
|
+
else
|
122
|
+
ost = OpenStruct.new
|
123
|
+
ost.freeze
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
def field_path
|
128
|
+
ConfigConvention.field_path(full_names.map{ |str| str.underscore })
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
class ConfigDef
|
133
|
+
attr_reader :key, :type, :desc, :path, :sample
|
134
|
+
def initialize(key, path, attributes = {})
|
135
|
+
@key = key.to_s
|
136
|
+
@path = path
|
137
|
+
@desc = attributes[:desc] || ""
|
138
|
+
@type = _type(attributes[:type])
|
139
|
+
@type_strict = _type_strict(@type)
|
140
|
+
@sample = attributes[:sample] || _sample(@type)
|
141
|
+
end
|
142
|
+
|
143
|
+
def field
|
144
|
+
"#{@path.join(".")}.#{@key}"
|
145
|
+
end
|
146
|
+
|
147
|
+
def value(v)
|
148
|
+
raise new NotPermitedValueType.new("#{path}.#{@key}: #{v} is NOT Matched Type for #{@type}") unless @type_strict.call(v)
|
149
|
+
v
|
150
|
+
end
|
151
|
+
|
152
|
+
private
|
153
|
+
def _type(t)
|
154
|
+
(t && t.downcase.to_sym) || :string
|
155
|
+
end
|
156
|
+
|
157
|
+
def _sample(type)
|
158
|
+
case type
|
159
|
+
when :string then; 'string'
|
160
|
+
when :int then; 0
|
161
|
+
when :float then; 0.1
|
162
|
+
when :boolean then; true
|
163
|
+
when :string_array then; ['string']
|
164
|
+
when :int_array then; [0]
|
165
|
+
when :float_array then; [0.1]
|
166
|
+
else
|
167
|
+
nil
|
168
|
+
end
|
169
|
+
end
|
170
|
+
def _type_strict(t)
|
171
|
+
case t
|
172
|
+
when :string then; -> (v){ v.is_a? String }
|
173
|
+
when :int then; -> (v){ v.is_a? Numeric }
|
174
|
+
when :float then; -> (v){ v.is_a? Numeric }
|
175
|
+
when :boolean then; -> (v){ v.is_a? TrueClass or v.is_a? FalseClass }
|
176
|
+
when :string_array then; -> (v){ v.is_a? Array and v.all?{ |s| s.is_a? String } }
|
177
|
+
when :int_array then; -> (v){ v.is_a? Array and v.all?{ |s| s.is_a? Numeric } }
|
178
|
+
when :float_array then; -> (v){ v.is_a? Array and v.all?{ |s| s.is_a? Numeric } }
|
179
|
+
else
|
180
|
+
raise NotPermitedValueType.new( "Type #{t} of Config Key:#{@key} - #{desc} in #{path}")
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
#-*- mode: ruby; coding: utf-8 -*-
|
2
|
+
|
3
|
+
|
4
|
+
#
|
5
|
+
# refer activesupport
|
6
|
+
#
|
7
|
+
# https://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/hash/deep_merge.rb
|
8
|
+
#
|
9
|
+
|
10
|
+
module ModulePlus
|
11
|
+
module CoreExt
|
12
|
+
module Hash
|
13
|
+
|
14
|
+
def deep_merge(other_hash, &block)
|
15
|
+
dup.deep_merge!(other_hash, &block)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Same as +deep_merge+, but modifies +self+.
|
19
|
+
def deep_merge!(other_hash, &block)
|
20
|
+
merge!(other_hash) do |key, this_val, other_val|
|
21
|
+
if this_val.is_a?(Hash) && other_val.is_a?(Hash)
|
22
|
+
this_val.deep_merge(other_val, &block)
|
23
|
+
elsif block_given?
|
24
|
+
block.call(key, this_val, other_val)
|
25
|
+
else
|
26
|
+
other_val
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class Hash
|
35
|
+
include ModulePlus::CoreExt::Hash
|
36
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# -*-mode: ruby; coding: utf-8 -*-
|
2
|
+
|
3
|
+
module ModulePlus
|
4
|
+
module CoreExt
|
5
|
+
module String
|
6
|
+
#
|
7
|
+
# Camel case string to under score string
|
8
|
+
#
|
9
|
+
# double column("::") to slash("/")
|
10
|
+
# dash("-") to underscore("_")
|
11
|
+
# reference ActiveSupport (MIT License)
|
12
|
+
# https://github.com/rails/rails/blob/master/activesupport/lib/active_support/inflector/methods.rb#L92
|
13
|
+
#
|
14
|
+
def self.underscore(origin)
|
15
|
+
return origin unless /[A-Z-]|::/.match?(origin)
|
16
|
+
word = origin.to_s.gsub('::', '/')
|
17
|
+
word.gsub!(acronyms_underscore_regex) { "#{$1 && '_'.freeze }#{$2.downcase}" }
|
18
|
+
word.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2'.freeze)
|
19
|
+
word.gsub!(/([a-z\d])([A-Z])/, '\1_\2'.freeze)
|
20
|
+
word.tr!("-".freeze, "_".freeze)
|
21
|
+
word.downcase!
|
22
|
+
word
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.acronyms_underscore_regex
|
26
|
+
/(?:(?<=([A-Za-z\d]))|\b)(#{acronym_regex})(?=\b|[^a-z])/
|
27
|
+
end
|
28
|
+
def self.acronym_regex
|
29
|
+
/(?=a)b/
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
class String
|
36
|
+
def underscore
|
37
|
+
ModulePlus::CoreExt::String.underscore(self)
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
#-*- mode: ruby; coding: utf-8 -*-
|
2
|
+
|
3
|
+
module ModulePlus
|
4
|
+
module Exception
|
5
|
+
class NotImplemented < StandardError; end
|
6
|
+
class CouldNotWrite < StandardError; end
|
7
|
+
class NotPermittedToInclude < StandardError; end
|
8
|
+
class NotPermittedToExtend < StandardError; end
|
9
|
+
class NotInitializedYet < StandardError; end
|
10
|
+
class NotPermitedValueType < StandardError; end
|
11
|
+
class NotFoundField < StandardError; end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
#-*- mode: ruby; coding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'module_plus/attribute'
|
4
|
+
require 'module_plus/exception'
|
5
|
+
|
6
|
+
module ModulePlus
|
7
|
+
module Identification
|
8
|
+
def full_name
|
9
|
+
my_klass.to_s
|
10
|
+
end
|
11
|
+
def full_names
|
12
|
+
full_name.split(/::/)
|
13
|
+
end
|
14
|
+
def nest_names
|
15
|
+
full_names.inject([]) do |list, name|
|
16
|
+
list << (list.empty? ? name : "#{list.last}::#{name}")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def root_name
|
21
|
+
nest_names.first
|
22
|
+
end
|
23
|
+
|
24
|
+
def outer_names
|
25
|
+
r = nest_names
|
26
|
+
r.take(r.size - 1)
|
27
|
+
end
|
28
|
+
|
29
|
+
def nests
|
30
|
+
#
|
31
|
+
nest_names.map { |name| eval(name) } # rubocop:disable Security/Eval
|
32
|
+
end
|
33
|
+
|
34
|
+
def root
|
35
|
+
eval(root_name) # rubocop:disable Security/Eval
|
36
|
+
end
|
37
|
+
|
38
|
+
def outers
|
39
|
+
outer_names.map { |n| eval(n) } # rubocop:disable Security/Eval
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
|
45
|
+
def my_klass
|
46
|
+
if self.is_a? Module
|
47
|
+
self
|
48
|
+
else
|
49
|
+
self.class
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/module_plus.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'module_plus/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'module_plus'
|
9
|
+
spec.version = ModulePlus::VERSION
|
10
|
+
spec.authors = ['satoyama']
|
11
|
+
spec.email = ['satoyama@linkode.co.jp']
|
12
|
+
|
13
|
+
spec.summary = 'Module + Utilities'
|
14
|
+
spec.description = 'To include/extend utilites for ruby "Module" or "Class".'
|
15
|
+
spec.homepage = 'https://github.com/linkodehub/module_plus'
|
16
|
+
spec.license = 'MIT'
|
17
|
+
|
18
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
19
|
+
f.match(%r{^(test|spec|features)/})
|
20
|
+
end
|
21
|
+
spec.bindir = 'exe'
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ['lib']
|
24
|
+
|
25
|
+
spec.add_development_dependency 'bundler', '~> 1.14'
|
26
|
+
spec.add_development_dependency 'pry'
|
27
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
28
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
29
|
+
spec.add_development_dependency 'rubocop'
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: module_plus
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- satoyama
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-02-01 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.14'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.14'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pry
|
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: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
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
|
+
description: To include/extend utilites for ruby "Module" or "Class".
|
84
|
+
email:
|
85
|
+
- satoyama@linkode.co.jp
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- ".rubocop.yml"
|
93
|
+
- ".travis.yml"
|
94
|
+
- CODE_OF_CONDUCT.md
|
95
|
+
- Gemfile
|
96
|
+
- LICENSE.txt
|
97
|
+
- README.md
|
98
|
+
- Rakefile
|
99
|
+
- bin/console
|
100
|
+
- bin/setup
|
101
|
+
- lib/module_plus.rb
|
102
|
+
- lib/module_plus/attribute.rb
|
103
|
+
- lib/module_plus/config_convention.rb
|
104
|
+
- lib/module_plus/core_ext/hash.rb
|
105
|
+
- lib/module_plus/core_ext/string.rb
|
106
|
+
- lib/module_plus/exception.rb
|
107
|
+
- lib/module_plus/identification.rb
|
108
|
+
- lib/module_plus/version.rb
|
109
|
+
- module_plus.gemspec
|
110
|
+
homepage: https://github.com/linkodehub/module_plus
|
111
|
+
licenses:
|
112
|
+
- MIT
|
113
|
+
metadata: {}
|
114
|
+
post_install_message:
|
115
|
+
rdoc_options: []
|
116
|
+
require_paths:
|
117
|
+
- lib
|
118
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - ">="
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
128
|
+
requirements: []
|
129
|
+
rubyforge_project:
|
130
|
+
rubygems_version: 2.7.3
|
131
|
+
signing_key:
|
132
|
+
specification_version: 4
|
133
|
+
summary: Module + Utilities
|
134
|
+
test_files: []
|