hexx-entities 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 +9 -0
- data/.yardopts +3 -0
- data/Gemfile +5 -0
- data/Guardfile +14 -0
- data/LICENSE +21 -0
- data/README.md +268 -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 +72 -0
- data/config/metrics/saikuro.yml +3 -0
- data/config/metrics/simplecov.yml +8 -0
- data/config/metrics/yardstick.yml +37 -0
- data/hexx-entities.gemspec +26 -0
- data/lib/hexx/entities/base.rb +76 -0
- data/lib/hexx/entities/uuid.rb +41 -0
- data/lib/hexx/entities/uuids.rb +34 -0
- data/lib/hexx/entities/version.rb +13 -0
- data/lib/hexx/entities.rb +14 -0
- data/lib/hexx-entities.rb +17 -0
- data/spec/spec_helper.rb +12 -0
- data/spec/tests/base_spec.rb +132 -0
- data/spec/tests/uuid_spec.rb +63 -0
- data/spec/tests/uuids_spec.rb +67 -0
- metadata +126 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0cfb1586f444fcffc282f8875fc0f158e93e190e
|
4
|
+
data.tar.gz: b7ed4909ae9aeb7cd0e91969d418e852dd80f063
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f4b9a371d643448b7a762f2797a1666ad10401d2f006de90250000fe869b03d28475c86b26d67bed7785a959e6ae65cf04cad84e090e785c42d1b434a7cfaeda
|
7
|
+
data.tar.gz: d4b415a67d586bd3fa957db482344a04b6713ac5e20d918c77864ff64c4b10445d68595be294fc3d1f18dfe02c628e6c2ba8aaf49eb5ffe7d56fb05d677ed4e5
|
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/tests/.+_spec\.rb$})
|
6
|
+
|
7
|
+
watch(%r{^lib/hexx/entities/(.+)\.rb}) do |m|
|
8
|
+
"spec/tests/#{ m[1] }_spec.rb"
|
9
|
+
end
|
10
|
+
|
11
|
+
watch(%r{^lib/\w+\.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,268 @@
|
|
1
|
+
Hexx::Entities
|
2
|
+
==============
|
3
|
+
|
4
|
+
[![Gem Version](https://img.shields.io/gem/v/hexx-entities.svg?style=flat)][gem]
|
5
|
+
[![Build Status](https://img.shields.io/travis/nepalez/hexx-entities/master.svg?style=flat)][travis]
|
6
|
+
[![Dependency Status](https://img.shields.io/gemnasium/nepalez/hexx-entities.svg?style=flat)][gemnasium]
|
7
|
+
[![Code Climate](https://img.shields.io/codeclimate/github/nepalez/hexx-entities.svg?style=flat)][codeclimate]
|
8
|
+
[![Coverage](https://img.shields.io/coveralls/nepalez/hexx-entities.svg?style=flat)][coveralls]
|
9
|
+
[![Inline docs](http://inch-ci.org/github/nepalez/hexx-entities.svg)][inch]
|
10
|
+
[![Documentation Status](https://readthedocs.org/projects/hexx-entities/badge/?version=latest)][readthedocs]
|
11
|
+
|
12
|
+
[codeclimate]: https://codeclimate.com/github/nepalez/hexx-entities
|
13
|
+
[coveralls]: https://coveralls.io/r/nepalez/hexx-entities
|
14
|
+
[gem]: https://rubygems.org/gems/hexx-entities
|
15
|
+
[gemnasium]: https://gemnasium.com/nepalez/hexx-entities
|
16
|
+
[inch]: https://inch-ci.org/github/nepalez/hexx-entities
|
17
|
+
[readthedocs]: https://hexx-entities.readthedocs.org
|
18
|
+
[travis]: https://travis-ci.org/nepalez/hexx-entities
|
19
|
+
|
20
|
+
Base class for domain entities:
|
21
|
+
|
22
|
+
* [synopsis](#synopsis)
|
23
|
+
* [istallation](#istallation)
|
24
|
+
* [usage](#usage)
|
25
|
+
* [compatibility](#compatibility)
|
26
|
+
* [contributing](#contributing)
|
27
|
+
* [license](#license)
|
28
|
+
|
29
|
+
Check the documentation at [Read the Docs]
|
30
|
+
|
31
|
+
Synopsis
|
32
|
+
--------
|
33
|
+
|
34
|
+
The [entity] describes (immutable) domain objects that have identity.
|
35
|
+
|
36
|
+
When descibing an entity you are expected to declare its attributes and
|
37
|
+
validations in the following way:
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
require "hexx-entities"
|
41
|
+
|
42
|
+
class Item < Hexx::Entities::Base
|
43
|
+
|
44
|
+
# Defines attributes with their coercers
|
45
|
+
attribute :foo, coerce: ->(value) { value.to_s }
|
46
|
+
attribute :bar
|
47
|
+
|
48
|
+
# Defines validation for the entity
|
49
|
+
validate { invalid :blank_foo unless foo }
|
50
|
+
validate { invalid :blank_bar unless bar }
|
51
|
+
|
52
|
+
end # class Item
|
53
|
+
|
54
|
+
item = Item.new foo: 1
|
55
|
+
item.attributes
|
56
|
+
# => { uuids: ["31a840f4-71e2-4de1-3a6f-04d2103aa2e8"], foo: "1", bar: nil }
|
57
|
+
item.validate!
|
58
|
+
# <Attestor::InvalidError> because bar is nil
|
59
|
+
```
|
60
|
+
|
61
|
+
Installation
|
62
|
+
------------
|
63
|
+
|
64
|
+
Add this line to your application's Gemfile:
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
# Gemfile
|
68
|
+
gem "hexx-entities"
|
69
|
+
```
|
70
|
+
|
71
|
+
Then execute:
|
72
|
+
|
73
|
+
```
|
74
|
+
bundle
|
75
|
+
```
|
76
|
+
|
77
|
+
Or add it manually:
|
78
|
+
|
79
|
+
```
|
80
|
+
gem install hexx-entities
|
81
|
+
```
|
82
|
+
|
83
|
+
Usage
|
84
|
+
-----
|
85
|
+
|
86
|
+
* [entity declaration](#declaration)
|
87
|
+
* [identity and equality](#identity-and-equality)
|
88
|
+
* [attributes and their initializer](#attributes-and-their-initializer)
|
89
|
+
* [validation](#validation)
|
90
|
+
* [serialization](#serialization)
|
91
|
+
|
92
|
+
### Entity Declaration
|
93
|
+
|
94
|
+
Define the entity as a subclass of `Hexx::Entities::Base`:
|
95
|
+
|
96
|
+
```ruby
|
97
|
+
class Item < Hexx::Entities::Base
|
98
|
+
end
|
99
|
+
```
|
100
|
+
|
101
|
+
### Identity and Equality
|
102
|
+
|
103
|
+
An entity is identified by its [uuids]. Uuids are either initialized,
|
104
|
+
or assigned by default:
|
105
|
+
|
106
|
+
[uuid]: https://en.wikipedia.org/wiki/Universally_unique_identifier
|
107
|
+
|
108
|
+
```ruby
|
109
|
+
entity = Item.new
|
110
|
+
entity.uuids # => ["31a840f4-71e2-4de1-3a6f-04d2103aa2e8"]
|
111
|
+
```
|
112
|
+
|
113
|
+
The entity is equal to any entity that responds to `uuids` and
|
114
|
+
has at least one uuid, that is equal to its own:
|
115
|
+
|
116
|
+
```ruby
|
117
|
+
a = Item.new uuids: [
|
118
|
+
"31a840f4-71e2-4de1-3a6f-04d2103aa2e8", # this value...
|
119
|
+
"78340523-8928-1ab0-0a3f-fa9eb07a7986"
|
120
|
+
]
|
121
|
+
|
122
|
+
b = Hexx::Entities::Base.new uuids: [
|
123
|
+
"9875023e-f483-cef9-ae09-27384015de79",
|
124
|
+
"31a840f4-71e2-4de1-3a6f-04d2103aa2e8" # ...is equal to this one
|
125
|
+
]
|
126
|
+
|
127
|
+
a == b # => true
|
128
|
+
```
|
129
|
+
|
130
|
+
Any uuid in the list is an instance of `Hexx::Entities::UUID` (kind of string).
|
131
|
+
The instance is validatable:
|
132
|
+
|
133
|
+
```ruby
|
134
|
+
uuid = Hexx::Entities::UUID.new "9875023e-f483-cef9-ae09-27384015de79"
|
135
|
+
# => "9875023e-f483-cef9-ae09-27384015de79"
|
136
|
+
uuid.validate! # passes
|
137
|
+
|
138
|
+
uuid = Hexx::Entities::UUID.new "not a valid uuid"
|
139
|
+
# => "not a valid uuid"
|
140
|
+
uuid.validate! # <Attestor::InvalidError>
|
141
|
+
```
|
142
|
+
|
143
|
+
### Attributes and their Initializer
|
144
|
+
|
145
|
+
The gem uses the [eigindir] library for attributes definition and coersion.
|
146
|
+
The `uuids` attribute is added by default.
|
147
|
+
|
148
|
+
All attributes can be initialized from hash:
|
149
|
+
|
150
|
+
```ruby
|
151
|
+
class Foo < Hexx::Entities::Base
|
152
|
+
|
153
|
+
attribute :bar
|
154
|
+
attribute :baz, coerce: ->(value) { value.to_s }
|
155
|
+
|
156
|
+
end
|
157
|
+
|
158
|
+
foo = Foo.new bar: :bar, "baz" => :baz
|
159
|
+
foo.attributes
|
160
|
+
# => { uuids: ["9875023e-f483-cef9-ae09-27384015de79"], bar: :bar, baz: "baz" }
|
161
|
+
```
|
162
|
+
|
163
|
+
[eigindir]: https://github.com/nepalez/eigindir
|
164
|
+
|
165
|
+
### Validation
|
166
|
+
|
167
|
+
The gem uses the [attestor] library for validation. Any entity is
|
168
|
+
a validatable object and responds to `#validate` and `#validate!` instance
|
169
|
+
methods.
|
170
|
+
|
171
|
+
Validation rules should be defined on class level with `.validate` helper,
|
172
|
+
or with the help of externam policy objects by `.validates` (with s) method:
|
173
|
+
|
174
|
+
```ruby
|
175
|
+
class Foo < Hexx::Entities::Base
|
176
|
+
|
177
|
+
attribute :bar
|
178
|
+
attribute :baz, coerce: ->(value) { Baz.new value }
|
179
|
+
|
180
|
+
validate { invalid :blank_bar unless bar }
|
181
|
+
# providing Baz responds to #validate! delegates validations:
|
182
|
+
validates :baz
|
183
|
+
|
184
|
+
end
|
185
|
+
```
|
186
|
+
|
187
|
+
Any enitiy is invalid when any of its uuids is invalid:
|
188
|
+
|
189
|
+
```ruby
|
190
|
+
Foo = Class.new Hexx::Entities::Base
|
191
|
+
foo = Foo.new uuids: ["invalid uuid"]
|
192
|
+
foo.validate! # <Attestor::InvalidError>
|
193
|
+
```
|
194
|
+
|
195
|
+
This is the only validation rule that is added to entity by default.
|
196
|
+
|
197
|
+
### Serialization
|
198
|
+
|
199
|
+
Entities can be converted to nested hash by the `serialize` method.
|
200
|
+
Any attribute is serialized recursively if it responds to `serialize` without
|
201
|
+
arguments:
|
202
|
+
|
203
|
+
```ruby
|
204
|
+
class Foo < Hexx::Entities::Base
|
205
|
+
|
206
|
+
attribute :bar, coerce: ->(value) { value.to_f }
|
207
|
+
attribute :baz, coerce: ->(value) { value.to_s }
|
208
|
+
|
209
|
+
end
|
210
|
+
|
211
|
+
class Qux < Hexx::Entities::Base
|
212
|
+
|
213
|
+
attribute :foo, coerce: ->(value) { Foo.new value }
|
214
|
+
attribute :qux
|
215
|
+
|
216
|
+
end
|
217
|
+
|
218
|
+
foo = Foo.new bar: 1, baz: 1
|
219
|
+
qux = Qux.new foo: foo
|
220
|
+
|
221
|
+
qux.serialize
|
222
|
+
# {
|
223
|
+
# uuids: ["78340523-8928-1ab0-0a3f-fa9eb07a7986"],
|
224
|
+
# foo: {
|
225
|
+
# uuids: ["31a840f4-71e2-4de1-3a6f-04d2103aa2e8"],
|
226
|
+
# bar: 1.0,
|
227
|
+
# baz: "1"
|
228
|
+
# }
|
229
|
+
# }
|
230
|
+
```
|
231
|
+
|
232
|
+
**Notice** the method is not protected against looping. In cases the later is
|
233
|
+
possible, you'd better to redefine the `serialize` method by itself with
|
234
|
+
custom protection.
|
235
|
+
|
236
|
+
Compatibility
|
237
|
+
-------------
|
238
|
+
|
239
|
+
Tested under [MRI rubies 2.1+](.travis.yml).
|
240
|
+
The module heavily uses [refinements], not yet supported by Rubinius and JRuby.
|
241
|
+
|
242
|
+
Backed on libraries:
|
243
|
+
* [eigindir] for defining attributes
|
244
|
+
* [attestor] for validations
|
245
|
+
|
246
|
+
Uses [RSpec] 3.0+ for testing and [hexx-suit] for dev/test tools collection.
|
247
|
+
|
248
|
+
[refinements]: http://ruby-doc.org/core-2.1.1/doc/syntax/refinements_rdoc.html
|
249
|
+
[attestor]: http://github.com/nepalez/attestor
|
250
|
+
[eigindir]: http://github.com/nepalez/eigindir
|
251
|
+
[RSpec]: http://rspec.org
|
252
|
+
[hexx-suit]: https://github.com/nepalez/hexx-suit
|
253
|
+
|
254
|
+
Contributing
|
255
|
+
------------
|
256
|
+
|
257
|
+
* Read the [STYLEGUIDE](config/metrics/STYLEGUIDE)
|
258
|
+
* [Fork the project](https://github.com/nepalez/hexx-entities)
|
259
|
+
* Create your feature branch (`git checkout -b my-new-feature`)
|
260
|
+
* Add tests for it
|
261
|
+
* Commit your changes (`git commit -am '[UPDATE] Add some feature'`)
|
262
|
+
* Push to the branch (`git push origin my-new-feature`)
|
263
|
+
* Create a new Pull Request
|
264
|
+
|
265
|
+
License
|
266
|
+
-------
|
267
|
+
|
268
|
+
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
|