hexx-api 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.coveralls.yml +2 -0
- data/.gitignore +9 -0
- data/.metrics +9 -0
- data/.rspec +2 -0
- data/.rubocop.yml +2 -0
- data/.travis.yml +11 -0
- data/.yardopts +3 -0
- data/Gemfile +7 -0
- data/Guardfile +14 -0
- data/LICENSE +21 -0
- data/README.md +94 -0
- data/Rakefile +22 -0
- data/config/metrics/STYLEGUIDE +230 -0
- data/config/metrics/cane.yml +5 -0
- data/config/metrics/churn.yml +6 -0
- data/config/metrics/flay.yml +2 -0
- data/config/metrics/metric_fu.yml +15 -0
- data/config/metrics/reek.yml +1 -0
- data/config/metrics/roodi.yml +24 -0
- data/config/metrics/rubocop.yml +73 -0
- data/config/metrics/saikuro.yml +3 -0
- data/config/metrics/simplecov.yml +8 -0
- data/config/metrics/yardstick.yml +37 -0
- data/hexx-api.gemspec +22 -0
- data/lib/hexx-api.rb +8 -0
- data/lib/hexx/api.rb +58 -0
- data/lib/hexx/api/version.rb +13 -0
- data/spec/spec_helper.rb +12 -0
- data/spec/tests/api_spec.rb +63 -0
- metadata +91 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 67708e2f9bdbe546b1e8f2ae9ce26dcde2bed764
|
4
|
+
data.tar.gz: 39015813747cee047b12ba10b974abdcba117a17
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1b6c3a5f119b53a8a1a698be02e66c956421960a3c11a013aa1ba829016ac3d4b26d67666b0fc08a542f630b950fd8aaa969e0676e47cab5ec85cf1af1ee7644
|
7
|
+
data.tar.gz: 501564ba741f7cf076b26572c56ee58179819907f812142b2b434b38b29ee6105d162846cd684a68f9ee78ef373bb97f6f0e364291e95d322c4cd090c9bfb943
|
data/.coveralls.yml
ADDED
data/.gitignore
ADDED
data/.metrics
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
# Settings for metric_fu and its packages are collected in the `config/metrics`
|
2
|
+
# and loaded by the Hexx::Suit::Metrics::MetricFu.
|
3
|
+
|
4
|
+
begin
|
5
|
+
require "hexx-suit"
|
6
|
+
Hexx::Suit::Metrics::MetricFu.load
|
7
|
+
rescue LoadError
|
8
|
+
puts "The 'hexx-suit' gem is not installed"
|
9
|
+
end
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/.yardopts
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
guard :rspec, cmd: "bundle exec rspec" do
|
4
|
+
|
5
|
+
watch(%r{^spec/.+_spec\.rb$})
|
6
|
+
|
7
|
+
watch(%r{^lib/hexx/(.+)\.rb$}) do |m|
|
8
|
+
"spec/tests/#{ m[1] }_spec.rb"
|
9
|
+
end
|
10
|
+
|
11
|
+
watch("lib/hexx-api.rb") { "spec" }
|
12
|
+
watch("spec/spec_helper.rb") { "spec" }
|
13
|
+
|
14
|
+
end # guard :rspec
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2015 Andrew Kozin (nepalez), andrew.kozin@gmail.com
|
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,94 @@
|
|
1
|
+
Hexx::API
|
2
|
+
=========
|
3
|
+
|
4
|
+
[![Gem Version](https://img.shields.io/gem/v/hexx-api.svg?style=flat)][gem]
|
5
|
+
[![Build Status](https://img.shields.io/travis/nepalez/hexx-api/master.svg?style=flat)][travis]
|
6
|
+
[![Dependency Status](https://img.shields.io/gemnasium/nepalez/hexx-api.svg?style=flat)][gemnasium]
|
7
|
+
[![Code Climate](https://img.shields.io/codeclimate/github/nepalez/hexx-api.svg?style=flat)][codeclimate]
|
8
|
+
[![Coverage](https://img.shields.io/coveralls/nepalez/hexx-api.svg?style=flat)][coveralls]
|
9
|
+
[![Inline docs](http://inch-ci.org/github/nepalez/hexx-api.svg)][inch]
|
10
|
+
|
11
|
+
[codeclimate]: https://codeclimate.com/github/nepalez/hexx-api
|
12
|
+
[coveralls]: https://coveralls.io/r/nepalez/hexx-api
|
13
|
+
[gem]: https://rubygems.org/gems/hexx-api
|
14
|
+
[gemnasium]: https://gemnasium.com/nepalez/hexx-api
|
15
|
+
[travis]: https://travis-ci.org/nepalez/hexx-api
|
16
|
+
[inch]: https://inch-ci.org/github/nepalez/hexx-api
|
17
|
+
|
18
|
+
The syntax sugar to wrap module content to kind of public API.
|
19
|
+
|
20
|
+
Synopsis
|
21
|
+
--------
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
# lib/my_module.rb
|
25
|
+
require "hexx-api"
|
26
|
+
|
27
|
+
# Load the code of the module (including some services)
|
28
|
+
require_relative "my_module/add_foo.rb"
|
29
|
+
require_relative "my_module/add_bar.rb"
|
30
|
+
# ...
|
31
|
+
|
32
|
+
# Provides public API for the module
|
33
|
+
module MyModule
|
34
|
+
extend Hexx::API
|
35
|
+
|
36
|
+
api_method :add_foo, :AddFoo # :new is the default method
|
37
|
+
api_method :add_bar, :AddBar, :build
|
38
|
+
end
|
39
|
+
```
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
MyModule[:add_foo]
|
43
|
+
# => Foo
|
44
|
+
|
45
|
+
MyModule.add_foo(*args)
|
46
|
+
# This is the same as AddFoo.new(*args)
|
47
|
+
|
48
|
+
MyModule[:add_bar]
|
49
|
+
# => Bar
|
50
|
+
|
51
|
+
MyModule.add_bar(*args)
|
52
|
+
# This is the same as AddBar.build(*args)
|
53
|
+
```
|
54
|
+
|
55
|
+
Installation
|
56
|
+
------------
|
57
|
+
|
58
|
+
Add this line to your application's Gemfile:
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
# Gemfile
|
62
|
+
gem "hexx-api"
|
63
|
+
```
|
64
|
+
|
65
|
+
Then execute:
|
66
|
+
|
67
|
+
```
|
68
|
+
bundle
|
69
|
+
```
|
70
|
+
|
71
|
+
Or add it manually:
|
72
|
+
|
73
|
+
```
|
74
|
+
gem install hexx-api
|
75
|
+
```
|
76
|
+
|
77
|
+
Compatibility
|
78
|
+
-------------
|
79
|
+
|
80
|
+
Tested under rubies compatible to API 1.9.2+:
|
81
|
+
|
82
|
+
* MRI 1.9.3+
|
83
|
+
* Rubinius-2+ (modes 1.9+)
|
84
|
+
* JRuby-1.7+
|
85
|
+
|
86
|
+
Uses [RSpec] 3.0+ for testing and [hexx-suit] for dev/test tools collection.
|
87
|
+
|
88
|
+
[RSpec]: http://rspec.info/
|
89
|
+
[hexx-suit]: http://github.com/nepalez/hexx-suit
|
90
|
+
|
91
|
+
License
|
92
|
+
-------
|
93
|
+
|
94
|
+
See the [MIT LICENSE](LICENSE).
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
begin
|
3
|
+
require "bundler/setup"
|
4
|
+
rescue LoadError
|
5
|
+
puts "You must `gem install bundler` and `bundle install` to run rake tasks"
|
6
|
+
exit
|
7
|
+
end
|
8
|
+
|
9
|
+
# Loads bundler tasks
|
10
|
+
Bundler::GemHelper.install_tasks
|
11
|
+
|
12
|
+
# Loads the Hexx::RSpec and its tasks
|
13
|
+
begin
|
14
|
+
require "hexx-suit"
|
15
|
+
Hexx::Suit.install_tasks
|
16
|
+
rescue LoadError
|
17
|
+
require "hexx-rspec"
|
18
|
+
Hexx::RSpec.install_tasks
|
19
|
+
end
|
20
|
+
|
21
|
+
# Sets the Hexx::RSpec :test task to default
|
22
|
+
task default: "test:coverage:run"
|
@@ -0,0 +1,230 @@
|
|
1
|
+
= Ruby Style Guide
|
2
|
+
|
3
|
+
Adapted from Dan Kubb's Ruby Style Guide
|
4
|
+
https://github.com/dkubb/styleguide/blob/master/RUBY-STYLE
|
5
|
+
|
6
|
+
== Commiting:
|
7
|
+
|
8
|
+
* Write descriptive commit messages, following the pattern:
|
9
|
+
|
10
|
+
[TYPE] name
|
11
|
+
|
12
|
+
The message, describing the changes being made
|
13
|
+
|
14
|
+
* Use the types below to mark commits:
|
15
|
+
|
16
|
+
- FEATURE - for adding new features, or backward-compatible changes;
|
17
|
+
- CHANGE - for backward-incompatible changes;
|
18
|
+
- BUG FIX - for fixing bugs;
|
19
|
+
- REFACTORING - for other changes of the code not affecting the API;
|
20
|
+
- OTHER - for changes in documentaton, metrics etc, not touching the code;
|
21
|
+
- VERSION - for version changes.
|
22
|
+
|
23
|
+
* Always separate commits of different types (such as FEATURE and CHANGE).
|
24
|
+
|
25
|
+
* Try to separate various features from each other.
|
26
|
+
|
27
|
+
* Include specification to the same commit as the code.
|
28
|
+
|
29
|
+
* Run all tests before making a commit.
|
30
|
+
Never commit the code that break unit tests.
|
31
|
+
|
32
|
+
* Use metric (run `rake check`) before making a commit.
|
33
|
+
|
34
|
+
* Do refactoring before making a commit. Best writing is rewriting.
|
35
|
+
|
36
|
+
* Follow semantic versioning.
|
37
|
+
|
38
|
+
http://semver.org/
|
39
|
+
|
40
|
+
* For versions name the commit after a version number, following the pattern:
|
41
|
+
|
42
|
+
VERSION 1.0.0-rc2
|
43
|
+
|
44
|
+
|
45
|
+
== Formatting:
|
46
|
+
|
47
|
+
* Use UTF-8. Declare encoding in the first line of every file.
|
48
|
+
|
49
|
+
# encoding: utf-8
|
50
|
+
|
51
|
+
* Use 2 space indent, no tabs.
|
52
|
+
|
53
|
+
* Use Unix-style line endings.
|
54
|
+
|
55
|
+
* Use spaces around operators, after commas, colons and semicolons,
|
56
|
+
around { and before }.
|
57
|
+
|
58
|
+
* No spaces after (, [ and before ], ).
|
59
|
+
|
60
|
+
* Align `when` and `else` with `case`.
|
61
|
+
|
62
|
+
* Use an empty line before the return value of a method (unless it
|
63
|
+
only has one line), and an empty line between defs.
|
64
|
+
|
65
|
+
* Use empty lines to break up a long method into logical paragraphs.
|
66
|
+
|
67
|
+
* Keep lines fewer than 80 characters.
|
68
|
+
|
69
|
+
* Strip trailing whitespace.
|
70
|
+
|
71
|
+
|
72
|
+
== Syntax:
|
73
|
+
|
74
|
+
* Write for 2.0.
|
75
|
+
|
76
|
+
* Use double quotes
|
77
|
+
|
78
|
+
http://viget.com/extend/just-use-double-quoted-ruby-strings
|
79
|
+
|
80
|
+
* Use def with parentheses when there are arguments.
|
81
|
+
|
82
|
+
* Never use for, unless you exactly know why.
|
83
|
+
|
84
|
+
* Never use then, except in case statements.
|
85
|
+
|
86
|
+
* Use when x then ... for one-line cases.
|
87
|
+
|
88
|
+
* Use &&/|| for boolean expressions, and/or for control flow. (Rule
|
89
|
+
of thumb: If you have to use outer parentheses, you are using the
|
90
|
+
wrong operators.)
|
91
|
+
|
92
|
+
* Avoid double negation (!!), unless Null Objects are expected.
|
93
|
+
|
94
|
+
http://devblog.avdi.org/2011/05/30/null-objects-and-falsiness
|
95
|
+
|
96
|
+
* Avoid multiline ?:, use if.
|
97
|
+
|
98
|
+
* Use {...} when defining blocks on one line. Use do...end for multiline
|
99
|
+
blocks.
|
100
|
+
|
101
|
+
* Avoid return where not required.
|
102
|
+
|
103
|
+
* Use ||= freely.
|
104
|
+
|
105
|
+
* Use OO regexps, and avoid =~ $0-9, $~, $` and $' when possible.
|
106
|
+
|
107
|
+
* Do not use Enumerable#inject when the "memo" object does not change between
|
108
|
+
iterations, use Enumerable#each_with_object instead (in ruby 1.9,
|
109
|
+
active_support and backports).
|
110
|
+
|
111
|
+
* Prefer ENV.fetch to ENV[] syntax.
|
112
|
+
Prefer block syntax for ENV.fetch to usage of the second argument.
|
113
|
+
|
114
|
+
|
115
|
+
== Naming:
|
116
|
+
|
117
|
+
* Use snake_case for methods.
|
118
|
+
|
119
|
+
* Use CamelCase for classes and modules. (Keep acronyms like HTTP,
|
120
|
+
RFC, XML uppercase.)
|
121
|
+
|
122
|
+
* Use SCREAMING_SNAKE_CASE for other constants.
|
123
|
+
|
124
|
+
* Do not use single letter variable names. Avoid uncommunicative names.
|
125
|
+
|
126
|
+
* Use consistent variable names. Try to keep the variable names close
|
127
|
+
to the object class name.
|
128
|
+
|
129
|
+
* Use names prefixed with _ for unused variables.
|
130
|
+
|
131
|
+
* When defining a predicate method that compares against another object of
|
132
|
+
a similar type, name the argument "other".
|
133
|
+
|
134
|
+
* Prefer map over collect, detect over find, select over find_all.
|
135
|
+
|
136
|
+
* Use def self.method to define singleton methods.
|
137
|
+
|
138
|
+
* Avoid alias when alias_method will do.
|
139
|
+
|
140
|
+
|
141
|
+
== Comments:
|
142
|
+
|
143
|
+
* Use YARD and its conventions for API documentation. Don't put an
|
144
|
+
empty line between the comment block and the def.
|
145
|
+
|
146
|
+
* Comments longer than a word are capitalized and use punctuation.
|
147
|
+
Use one space after periods.
|
148
|
+
|
149
|
+
* Avoid superfluous comments.
|
150
|
+
|
151
|
+
|
152
|
+
== Code structuring:
|
153
|
+
|
154
|
+
* Break code into packages, decoupled from the environment.
|
155
|
+
|
156
|
+
* Wrap packages into gems.
|
157
|
+
|
158
|
+
* Inject dependencies explicitly.
|
159
|
+
Leave all outer references on the border of any package. Inside
|
160
|
+
the package use internal references only.
|
161
|
+
|
162
|
+
* Follow SOLID principles.
|
163
|
+
|
164
|
+
http://en.wikipedia.org/wiki/SOLID_(object-oriented_design)
|
165
|
+
|
166
|
+
* Only give a method one purpose for existing. If you pass in a boolean
|
167
|
+
to a method, what you're saying is that this method has two different
|
168
|
+
behaviours. Just split it into two single purpose methods. If you have
|
169
|
+
to use the words "AND" or "OR" to describe what the method does it
|
170
|
+
probably does too much.
|
171
|
+
|
172
|
+
* Avoid long methods.
|
173
|
+
Try to keep them at no more than 6 lines long, and preferably 4 or less.
|
174
|
+
|
175
|
+
If sections of a method are logically separate by blank lines, then
|
176
|
+
that's probably a sign that those sections should be split into separate
|
177
|
+
methods.
|
178
|
+
|
179
|
+
* Avoid hashes-as-optional-parameters. Does the method do too much?
|
180
|
+
|
181
|
+
* Avoid long parameter lists.
|
182
|
+
|
183
|
+
* Add "global" methods to Kernel (if you have to) and make them private.
|
184
|
+
|
185
|
+
* Use OptionParser for parsing complex command line options and
|
186
|
+
ruby -s for trivial command line options.
|
187
|
+
|
188
|
+
* Avoid needless metaprogramming.
|
189
|
+
|
190
|
+
* Always freeze objects assigned to constants.
|
191
|
+
|
192
|
+
|
193
|
+
== General:
|
194
|
+
|
195
|
+
* Code in a functional way, avoid mutation when it makes sense.
|
196
|
+
|
197
|
+
* Try to have methods either return the state of the object and have
|
198
|
+
no side effects, or return self and have side effects. This is
|
199
|
+
otherwise known as Command-query separation (CQS):
|
200
|
+
|
201
|
+
http://en.wikipedia.org/wiki/Command-query_separation
|
202
|
+
|
203
|
+
* Do not mutate arguments unless that is the purpose of the method.
|
204
|
+
|
205
|
+
* Try following TRUE heuristics by Sandi Metz
|
206
|
+
|
207
|
+
http://designisrefactoring.com/2015/02/08/introducing-sandi-metz-true/
|
208
|
+
|
209
|
+
* Do not mess around in core classes when writing libraries.
|
210
|
+
Namespace your code inside the modules, or wrap core classes to
|
211
|
+
decorators of your own.
|
212
|
+
|
213
|
+
* Do not program defensively.
|
214
|
+
|
215
|
+
http://www.erlang.se/doc/programming_rules.shtml#HDR11
|
216
|
+
|
217
|
+
* Keep the code simple.
|
218
|
+
|
219
|
+
* Don't overdesign.
|
220
|
+
|
221
|
+
* Don't underdesign.
|
222
|
+
|
223
|
+
* Avoid bugs.
|
224
|
+
|
225
|
+
* Read other style guides and apply the parts that don't dissent with
|
226
|
+
this list.
|
227
|
+
|
228
|
+
* Be consistent.
|
229
|
+
|
230
|
+
* Use common sense.
|
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
folders: # The list of folders to be used by any metric.
|
3
|
+
- lib
|
4
|
+
- app
|
5
|
+
metrics: # The list of allowed metrics. The other metrics are disabled.
|
6
|
+
- cane
|
7
|
+
- churn
|
8
|
+
- flay
|
9
|
+
- flog
|
10
|
+
- reek
|
11
|
+
- roodi
|
12
|
+
- saikuro
|
13
|
+
format: html
|
14
|
+
output: tmp/metric_fu
|
15
|
+
verbose: false
|
@@ -0,0 +1 @@
|
|
1
|
+
---
|
@@ -0,0 +1,24 @@
|
|
1
|
+
---
|
2
|
+
AssignmentInConditionalCheck:
|
3
|
+
CaseMissingElseCheck:
|
4
|
+
ClassLineCountCheck:
|
5
|
+
line_count: 300
|
6
|
+
ClassNameCheck:
|
7
|
+
pattern: !ruby/regexp /^[A-Z][a-zA-Z0-9]*$/
|
8
|
+
ClassVariableCheck:
|
9
|
+
CyclomaticComplexityBlockCheck:
|
10
|
+
complexity: 4
|
11
|
+
CyclomaticComplexityMethodCheck:
|
12
|
+
complexity: 8
|
13
|
+
EmptyRescueBodyCheck:
|
14
|
+
ForLoopCheck:
|
15
|
+
MethodLineCountCheck:
|
16
|
+
line_count: 20
|
17
|
+
MethodNameCheck:
|
18
|
+
pattern: !ruby/regexp /^[\||\^|\&|\!]$|^[_a-z<>=\[|+-\/\*`]+[_a-z0-9_<>=~@\[\]]*[=!\?]?$/
|
19
|
+
ModuleLineCountCheck:
|
20
|
+
line_count: 300
|
21
|
+
ModuleNameCheck:
|
22
|
+
pattern: !ruby/regexp /^[A-Z][a-zA-Z0-9]*$/
|
23
|
+
ParameterNumberCheck:
|
24
|
+
parameter_count: 5
|
@@ -0,0 +1,73 @@
|
|
1
|
+
---
|
2
|
+
# settings added by the 'hexx-suit' module
|
3
|
+
# output: "tmp/rubocop"
|
4
|
+
# format: "html"
|
5
|
+
|
6
|
+
AllCops:
|
7
|
+
Exclude:
|
8
|
+
- '**/db/schema.rb'
|
9
|
+
|
10
|
+
Lint/HandleExceptions:
|
11
|
+
Exclude:
|
12
|
+
- '**/*_spec.rb'
|
13
|
+
|
14
|
+
Lint/RescueException:
|
15
|
+
Exclude:
|
16
|
+
- '**/*_spec.rb'
|
17
|
+
|
18
|
+
Style/AccessorMethodName:
|
19
|
+
Exclude:
|
20
|
+
- '**/*_spec.rb'
|
21
|
+
|
22
|
+
Style/AsciiComments:
|
23
|
+
Enabled: false
|
24
|
+
|
25
|
+
Style/ClassAndModuleChildren:
|
26
|
+
Exclude:
|
27
|
+
- '**/*_spec.rb'
|
28
|
+
|
29
|
+
Style/Documentation:
|
30
|
+
Enabled: false
|
31
|
+
|
32
|
+
Style/EmptyLinesAroundBlockBody:
|
33
|
+
Enabled: false
|
34
|
+
|
35
|
+
Style/EmptyLinesAroundClassBody:
|
36
|
+
Enabled: false
|
37
|
+
|
38
|
+
Style/EmptyLinesAroundMethodBody:
|
39
|
+
Enabled: false
|
40
|
+
|
41
|
+
Style/EmptyLinesAroundModuleBody:
|
42
|
+
Enabled: false
|
43
|
+
|
44
|
+
Style/EmptyLineBetweenDefs:
|
45
|
+
Enabled: false
|
46
|
+
|
47
|
+
Style/FileName:
|
48
|
+
Enabled: false
|
49
|
+
|
50
|
+
Style/RaiseArgs:
|
51
|
+
EnforcedStyle: compact
|
52
|
+
|
53
|
+
Style/SingleLineMethods:
|
54
|
+
Exclude:
|
55
|
+
- '**/*_spec.rb'
|
56
|
+
|
57
|
+
Style/SingleSpaceBeforeFirstArg:
|
58
|
+
Enabled: false
|
59
|
+
|
60
|
+
Style/SpecialGlobalVars:
|
61
|
+
Exclude:
|
62
|
+
- '**/Gemfile'
|
63
|
+
- '**/*.gemspec'
|
64
|
+
|
65
|
+
Style/StringLiterals:
|
66
|
+
EnforcedStyle: double_quotes
|
67
|
+
|
68
|
+
Style/StringLiteralsInInterpolation:
|
69
|
+
EnforcedStyle: double_quotes
|
70
|
+
|
71
|
+
Style/TrivialAccessors:
|
72
|
+
Exclude:
|
73
|
+
- '**/*_spec.rb'
|
@@ -0,0 +1,37 @@
|
|
1
|
+
---
|
2
|
+
# Settings added by the 'hexx-suit' gem
|
3
|
+
output: "tmp/yardstick/output.log"
|
4
|
+
path: "lib/**/*.rb"
|
5
|
+
rules:
|
6
|
+
ApiTag::Presence:
|
7
|
+
enabled: true
|
8
|
+
exclude: []
|
9
|
+
ApiTag::Inclusion:
|
10
|
+
enabled: true
|
11
|
+
exclude: []
|
12
|
+
ApiTag::ProtectedMethod:
|
13
|
+
enabled: true
|
14
|
+
exclude: []
|
15
|
+
ApiTag::PrivateMethod:
|
16
|
+
enabled: false
|
17
|
+
exclude: []
|
18
|
+
ExampleTag:
|
19
|
+
enabled: true
|
20
|
+
exclude: []
|
21
|
+
ReturnTag:
|
22
|
+
enabled: true
|
23
|
+
exclude: []
|
24
|
+
Summary::Presence:
|
25
|
+
enabled: true
|
26
|
+
exclude: []
|
27
|
+
Summary::Length:
|
28
|
+
enabled: true
|
29
|
+
exclude: []
|
30
|
+
Summary::Delimiter:
|
31
|
+
enabled: true
|
32
|
+
exclude: []
|
33
|
+
Summary::SingleLine:
|
34
|
+
enabled: true
|
35
|
+
exclude: []
|
36
|
+
threshold: 100
|
37
|
+
verbose: false
|
data/hexx-api.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
2
|
+
require "hexx/api/version"
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
|
6
|
+
gem.name = "hexx-api"
|
7
|
+
gem.version = Hexx::API::VERSION.dup
|
8
|
+
gem.author = "Andrew Kozin"
|
9
|
+
gem.email = "andrew.kozin@gmail.com"
|
10
|
+
gem.homepage = "https://github.com/nepalez/hexx-api"
|
11
|
+
gem.summary = "Features to provide public API for the gem"
|
12
|
+
gem.license = "MIT"
|
13
|
+
|
14
|
+
gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
15
|
+
gem.test_files = Dir["spec/**/*.rb"]
|
16
|
+
gem.extra_rdoc_files = Dir["README.md", "LICENSE"]
|
17
|
+
gem.require_paths = ["lib"]
|
18
|
+
|
19
|
+
gem.required_ruby_version = "~> 2.1"
|
20
|
+
gem.add_development_dependency "hexx-rspec"
|
21
|
+
|
22
|
+
end # Gem::Specification
|
data/lib/hexx-api.rb
ADDED
data/lib/hexx/api.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Hexx
|
4
|
+
|
5
|
+
# Features to convert a module to API
|
6
|
+
#
|
7
|
+
# @example
|
8
|
+
# module MyModule
|
9
|
+
# extend Hexx::API
|
10
|
+
#
|
11
|
+
# api_method :foo, Foo
|
12
|
+
# api_method :bar, Bar, :build
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
# MyModule[:foo] # => Foo
|
16
|
+
# MyModule.foo(*args) # => Foo.new(*args)
|
17
|
+
#
|
18
|
+
# MyModule[:bar] # => Bar
|
19
|
+
# MyModule.bar(*args) # => Bar.build(*args)
|
20
|
+
module API
|
21
|
+
|
22
|
+
# Returns the constant defined by API
|
23
|
+
#
|
24
|
+
# @param [#to_sym] name
|
25
|
+
#
|
26
|
+
# @return [Object]
|
27
|
+
def [](name)
|
28
|
+
__api__[name.to_sym]
|
29
|
+
end
|
30
|
+
|
31
|
+
# Defines the named method of API
|
32
|
+
#
|
33
|
+
# @param [#to_sym] name The name of the API method
|
34
|
+
# @param [Object] type The type of the object to be returned by #{[]}
|
35
|
+
# @param [String, Symbol] method
|
36
|
+
# The name of the type method, that should be called by API name
|
37
|
+
#
|
38
|
+
# @return [self] itself
|
39
|
+
def api_method(name, type, method = :new)
|
40
|
+
__api__[name.to_sym] = type
|
41
|
+
singleton_class.__send__(:define_method, name) do |*args|
|
42
|
+
type.public_send method, *args
|
43
|
+
end
|
44
|
+
|
45
|
+
self
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
attr_reader :__api__
|
51
|
+
|
52
|
+
def __api__
|
53
|
+
@__api__ ||= {}
|
54
|
+
end
|
55
|
+
|
56
|
+
end # module API
|
57
|
+
|
58
|
+
end # module Hexx
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
describe Hexx::API do
|
4
|
+
|
5
|
+
let(:test) { Module.new.extend described_class }
|
6
|
+
let(:foo) { double :foo, new: :foo, bar: :baz }
|
7
|
+
|
8
|
+
before { described_class::Foo = foo }
|
9
|
+
after { described_class.send :remove_const, :Foo }
|
10
|
+
|
11
|
+
describe ".[]" do
|
12
|
+
|
13
|
+
subject { test[:foo] }
|
14
|
+
|
15
|
+
it "returns nil by default" do
|
16
|
+
expect(subject).to be_nil
|
17
|
+
end
|
18
|
+
|
19
|
+
end # describe .[]
|
20
|
+
|
21
|
+
describe ".api_method" do
|
22
|
+
|
23
|
+
let(:args) { [:qux, :quxx, :quxxx] }
|
24
|
+
|
25
|
+
context "without third argument" do
|
26
|
+
|
27
|
+
subject { test.api_method :foo, foo }
|
28
|
+
|
29
|
+
it "defines [:foo]" do
|
30
|
+
expect { subject }.to change { test[:foo] }.from(nil).to(foo)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "defines ['foo']" do
|
34
|
+
expect { subject }.to change { test["foo"] }.from(nil).to(foo)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "defines #foo as [:foo].new" do
|
38
|
+
subject
|
39
|
+
expect(foo).to receive(:new).with(*args)
|
40
|
+
expect(test.foo(*args)).to eq :foo
|
41
|
+
end
|
42
|
+
|
43
|
+
end # context
|
44
|
+
|
45
|
+
context "with third argument" do
|
46
|
+
|
47
|
+
subject { test.api_method "foo", foo, :bar }
|
48
|
+
|
49
|
+
it "defines [:foo]" do
|
50
|
+
expect { subject }.to change { test[:foo] }.from(nil).to(foo)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "defines #foo as custom method" do
|
54
|
+
subject
|
55
|
+
expect(foo).to receive(:bar).with(*args)
|
56
|
+
expect(test.foo(*args)).to eq :baz
|
57
|
+
end
|
58
|
+
|
59
|
+
end # context
|
60
|
+
|
61
|
+
end # describe .api_method
|
62
|
+
|
63
|
+
end # describe Hexx::API
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hexx-api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrew Kozin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: hexx-rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description:
|
28
|
+
email: andrew.kozin@gmail.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files:
|
32
|
+
- README.md
|
33
|
+
- LICENSE
|
34
|
+
files:
|
35
|
+
- ".coveralls.yml"
|
36
|
+
- ".gitignore"
|
37
|
+
- ".metrics"
|
38
|
+
- ".rspec"
|
39
|
+
- ".rubocop.yml"
|
40
|
+
- ".travis.yml"
|
41
|
+
- ".yardopts"
|
42
|
+
- Gemfile
|
43
|
+
- Guardfile
|
44
|
+
- LICENSE
|
45
|
+
- README.md
|
46
|
+
- Rakefile
|
47
|
+
- config/metrics/STYLEGUIDE
|
48
|
+
- config/metrics/cane.yml
|
49
|
+
- config/metrics/churn.yml
|
50
|
+
- config/metrics/flay.yml
|
51
|
+
- config/metrics/metric_fu.yml
|
52
|
+
- config/metrics/reek.yml
|
53
|
+
- config/metrics/roodi.yml
|
54
|
+
- config/metrics/rubocop.yml
|
55
|
+
- config/metrics/saikuro.yml
|
56
|
+
- config/metrics/simplecov.yml
|
57
|
+
- config/metrics/yardstick.yml
|
58
|
+
- hexx-api.gemspec
|
59
|
+
- lib/hexx-api.rb
|
60
|
+
- lib/hexx/api.rb
|
61
|
+
- lib/hexx/api/version.rb
|
62
|
+
- spec/spec_helper.rb
|
63
|
+
- spec/tests/api_spec.rb
|
64
|
+
homepage: https://github.com/nepalez/hexx-api
|
65
|
+
licenses:
|
66
|
+
- MIT
|
67
|
+
metadata: {}
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options: []
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - "~>"
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '2.1'
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
requirements: []
|
83
|
+
rubyforge_project:
|
84
|
+
rubygems_version: 2.4.6
|
85
|
+
signing_key:
|
86
|
+
specification_version: 4
|
87
|
+
summary: Features to provide public API for the gem
|
88
|
+
test_files:
|
89
|
+
- spec/spec_helper.rb
|
90
|
+
- spec/tests/api_spec.rb
|
91
|
+
has_rdoc:
|