hexx 7.1.0 → 8.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/.coveralls.yml +2 -0
  3. data/.gitignore +9 -0
  4. data/.metrics +5 -0
  5. data/.rspec +2 -0
  6. data/.rubocop.yml +2 -63
  7. data/.travis.yml +5 -0
  8. data/.yardopts +2 -0
  9. data/Gemfile +3 -0
  10. data/Guardfile +16 -0
  11. data/{LICENSE.rdoc → LICENSE} +2 -2
  12. data/README.md +138 -0
  13. data/Rakefile +8 -14
  14. data/config/initializer.rb +5 -0
  15. data/config/initializers/capture.rb +19 -0
  16. data/config/initializers/sandbox.rb +16 -0
  17. data/config/initializers/sandbox/helpers.rb +38 -0
  18. data/config/initializers/sandbox/matchers.rb +19 -0
  19. data/config/metrics/STYLEGUIDE +230 -0
  20. data/config/metrics/cane.yml +5 -0
  21. data/config/metrics/churn.yml +6 -0
  22. data/config/metrics/flay.yml +2 -0
  23. data/config/metrics/metric_fu.yml +15 -0
  24. data/config/metrics/pippi.yml +3 -0
  25. data/config/metrics/reek.yml +1 -0
  26. data/config/metrics/roodi.yml +24 -0
  27. data/config/metrics/rubocop.yml +79 -0
  28. data/config/metrics/saikuro.yml +3 -0
  29. data/config/metrics/simplecov.yml +6 -0
  30. data/config/metrics/yardstick.yml +37 -0
  31. data/hexx.gemspec +24 -0
  32. data/lib/hexx.rb +8 -15
  33. data/lib/hexx/generator.rb +71 -0
  34. data/lib/hexx/generator/file.rb +83 -0
  35. data/lib/hexx/generator/folder.rb +68 -0
  36. data/lib/hexx/name.rb +122 -46
  37. data/lib/hexx/version.rb +6 -5
  38. data/spec/fixtures/root/_.beta +1 -0
  39. data/spec/fixtures/root/__omega +0 -0
  40. data/spec/fixtures/root/delta.erb.erb +0 -0
  41. data/spec/fixtures/root/gamma.rb.erb +1 -0
  42. data/spec/fixtures/root/subfolder/alfa.yml +0 -0
  43. data/spec/spec_helper.rb +5 -10
  44. data/spec/tests/lib/generator_spec.rb +126 -0
  45. data/spec/tests/lib/name_spec.rb +113 -0
  46. metadata +54 -168
  47. data/README.rdoc +0 -371
  48. data/lib/hexx/coercible.rb +0 -43
  49. data/lib/hexx/configurable.rb +0 -101
  50. data/lib/hexx/creators/base.rb +0 -103
  51. data/lib/hexx/creators/coercion.rb +0 -82
  52. data/lib/hexx/creators/dependency.rb +0 -87
  53. data/lib/hexx/creators/module_dependency.rb +0 -57
  54. data/lib/hexx/creators/parameter.rb +0 -40
  55. data/lib/hexx/dependable.rb +0 -51
  56. data/lib/hexx/helpers/exceptions.rb +0 -53
  57. data/lib/hexx/helpers/messages.rb +0 -26
  58. data/lib/hexx/helpers/parameters.rb +0 -47
  59. data/lib/hexx/helpers/validations.rb +0 -21
  60. data/lib/hexx/message.rb +0 -79
  61. data/lib/hexx/null.rb +0 -218
  62. data/lib/hexx/service.rb +0 -388
  63. data/lib/hexx/service/with_callbacks.rb +0 -104
  64. data/lib/hexx/service_invalid.rb +0 -73
  65. data/spec/hexx/coercible_spec.rb +0 -72
  66. data/spec/hexx/configurable_spec.rb +0 -93
  67. data/spec/hexx/dependable_spec.rb +0 -125
  68. data/spec/hexx/helpers/exceptions_spec.rb +0 -96
  69. data/spec/hexx/helpers/messages_spec.rb +0 -48
  70. data/spec/hexx/helpers/parameters_spec.rb +0 -96
  71. data/spec/hexx/helpers/validations_spec.rb +0 -32
  72. data/spec/hexx/message_spec.rb +0 -83
  73. data/spec/hexx/name_spec.rb +0 -80
  74. data/spec/hexx/null_spec.rb +0 -152
  75. data/spec/hexx/service_invalid_spec.rb +0 -46
  76. data/spec/hexx/service_spec.rb +0 -89
  77. data/spec/support/initializers/focus.rb +0 -5
  78. data/spec/support/initializers/garbage_collection.rb +0 -11
  79. data/spec/support/initializers/i18n.rb +0 -3
  80. data/spec/support/initializers/random_order.rb +0 -4
  81. data/spec/support/initializers/rspec.rb +0 -5
  82. data/spec/support/matchers/methods.rb +0 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8b0ca93b80a2f6c0c3748f0a273d9edda36972ba
4
- data.tar.gz: 19527f2b06838db356f0bb99df053671bc1fce70
3
+ metadata.gz: 8d625ece05916e9121d6f01b3303115353579035
4
+ data.tar.gz: 8b8c07916d45bf1d6078651ef0a332a6342266fe
5
5
  SHA512:
6
- metadata.gz: 74c24d5eed54e869db7b3fdcbfe9cfbe3b3e1f8fa11cb287c2c51b9c9cc568ec7b067894526b2d68de238c78d94398fbf4d080a6ccd3e5b6c31bdc31b49ea945
7
- data.tar.gz: d66c7f7a5eb5dbc20b2b1fdf78c53fdbaa99c36290267fddf1941cc7634af2dd5a072650d2546d78c9dc7b34004215c05fd3755fdfd293bc02bad7afe6fb69d3
6
+ metadata.gz: 4978c9fc8738e710b4009737c890a0d6196e703f9a4aae9d2e8035bf7803bc4e7b98783e4d2a09f962886d1724e185f84b7aaf80556e75736a30bac9459a2d4e
7
+ data.tar.gz: b86403c6865eb3cb4b0ddd28fd9b8ca3afcff359fcb506fac7f54301b5c76a517cc795a3260c7e0bd4542b0ff38c3e6f757da3939da858745b67c3c08294ca5c
@@ -0,0 +1,2 @@
1
+ ---
2
+ service_name: travis-ci
@@ -0,0 +1,9 @@
1
+ *.gem
2
+ *.lock
3
+ .bundle/
4
+ .yardoc/
5
+ coverage/
6
+ doc/
7
+ log/
8
+ pkg/
9
+ tmp/
@@ -0,0 +1,5 @@
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
+ require "hexx-suit"
5
+ Hexx::Suit::Metrics::MetricFu.load
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --require spec_helper
2
+ --color
@@ -1,63 +1,2 @@
1
- Lint/HandleExceptions:
2
- Exclude:
3
- - 'spec/**/*'
4
-
5
- Lint/RescueException:
6
- Exclude:
7
- - 'spec/**/*'
8
-
9
- Metrics/ClassLength:
10
- Exclude:
11
- - 'lib/generators/**/*.rb'
12
-
13
- Style/AccessorMethodName:
14
- Exclude:
15
- - 'spec/**/*'
16
-
17
- Style/AsciiComments:
18
- Enabled: false
19
-
20
- Style/ClassAndModuleChildren:
21
- Exclude:
22
- - 'spec/**/*'
23
-
24
- Style/Documentation:
25
- Exclude:
26
- - 'spec/**/*'
27
-
28
- Style/EmptyLinesAroundBlockBody:
29
- Enabled: false
30
-
31
- Style/EmptyLinesAroundClassBody:
32
- Enabled: false
33
-
34
- Style/EmptyLinesAroundMethodBody:
35
- Enabled: false
36
-
37
- Style/EmptyLinesAroundModuleBody:
38
- Enabled: false
39
-
40
- Style/EmptyLineBetweenDefs:
41
- Enabled: false
42
-
43
- Style/RaiseArgs:
44
- EnforcedStyle: compact
45
-
46
- Style/SingleLineMethods:
47
- Exclude:
48
- - 'spec/**/*'
49
-
50
- Style/SpecialGlobalVars:
51
- Exclude:
52
- - 'Gemfile'
53
- - '*.gemspec'
54
-
55
- Style/StringLiterals:
56
- EnforcedStyle: double_quotes
57
-
58
- Stype/SingleSpaceBeforeFirstArg:
59
- Enabled: false
60
-
61
- Style/TrivialAccessors:
62
- Exclude:
63
- - 'spec/**/*'
1
+ ---
2
+ inherit_from: "./config/metrics/rubocop.yml"
@@ -0,0 +1,5 @@
1
+ ---
2
+ language: ruby
3
+ rvm:
4
+ - '2.1'
5
+ - '2.2'
@@ -0,0 +1,2 @@
1
+ --asset LICENSE
2
+ --out doc/api
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
@@ -0,0 +1,16 @@
1
+ # encoding: utf-8
2
+
3
+ guard :rspec, cmd: "bundle exec rspec spec" do
4
+
5
+ watch("lib/hexx.rb") { "spec" }
6
+
7
+ watch(%r{^lib/hexx/(\w+)\.rb$}) do |m|
8
+ "spec/tests/lib/#{ m[1] }_spec.rb"
9
+ end
10
+
11
+ watch("spec/tests/**/*_spec.rb")
12
+
13
+ watch("spec/fixtures/**/*") { "spec" }
14
+
15
+ watch("spec/spec_helper.rb") { "spec" }
16
+ end
@@ -1,6 +1,6 @@
1
- = The MIT License
1
+ The MIT License
2
2
 
3
- Copyright (c) 2014 Andrew Kozin, https://github.com/nepalez
3
+ Copyright (c) 2015 Andrew Kozin, andrew.kozin@gmail.com
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -0,0 +1,138 @@
1
+ # Hexx
2
+
3
+ [![Gem Version](https://img.shields.io/gem/v/hexx.svg?style=flat)][gem]
4
+ [![Build Status](https://img.shields.io/travis/nepalez/hexx/master.svg?style=flat)][travis]
5
+ [![Dependency Status](https://img.shields.io/gemnasium/nepalez/hexx.svg?style=flat)][gemnasium]
6
+ [![Code Climate](https://img.shields.io/codeclimate/github/nepalez/hexx.svg?style=flat)][codeclimate]
7
+ [![Coverage](https://img.shields.io/coveralls/nepalez/hexx.svg?style=flat)][coveralls]
8
+ [![License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat)][MIT LICENSE]
9
+
10
+ [MIT LICENSE]: file:./LICENSE
11
+ [codeclimate]: https://codeclimate.com/github/nepalez/hexx
12
+ [coveralls]: https://coveralls.io/r/nepalez/hexx
13
+ [gem]: https://rubygems.org/gems/hexx
14
+ [gemnasium]: https://gemnasium.com/nepalez/hexx
15
+ [travis]: https://travis-ci.org/nepalez/hexx
16
+
17
+ Collection of scaffolders for projects, that follows the [Hexagonal Architecture].
18
+
19
+ [Hexagonal Architecture]: http://alistair.cockburn.us/Hexagonal+architecture
20
+
21
+ ## Introduction
22
+
23
+ **The collection is neither a framework, nor library by itself**. I widely use external libraries, such as [activemodel], [virtus], [rom-rb], [wisper], [service_objects] etc.
24
+
25
+ The **goal of the gem** is not to add new features but fix their usage as personal reusable standards of coding and testing applications.
26
+
27
+ I structure applications by types of objects such as entities, services, validators, parsers etc. - exactly in the same way as accepted in [Rails]. When faced to new type of objects, I immediately create a new scaffolder and play with it for some time - until it becomes a standard I will follow afterwards.
28
+
29
+ To apply [TDD] scaffolders generate specifications in [RSpec]. Both the specification and code are commented - they should be reviewed and uncommented after creation. Scaffolders follow [Yard] style when generate documentation.
30
+
31
+ You're welcome to propose your own best (or even better) practices to be shared standards.
32
+
33
+ [IoC container]: http://www.martinfowler.com/articles/injection.html#FormsOfDependencyInjection
34
+ [RSpec]: http://rspec.info
35
+ [Rails]: http://rubyonrails.org
36
+ [TDD]: https://en.wikipedia.org/wiki/Test-driven_development
37
+ [Yard]: http://yardoc.org
38
+ [activemodel]: https://rubygems.org/gems/activemodel
39
+ [rom-rb]: http://rom-rb.org
40
+ [service_objects]: https://github.com/nepalez/service_objects
41
+ [virtus]: https://github.com/solnic/virtus
42
+ [wisper]: https://github.com/krisleech/wisper
43
+
44
+ ## Content
45
+
46
+ The core module defines:
47
+
48
+ * `Hexx::Generator` - The base class for the scaffolders, that inherits `Thor::Group` and extends it with additional methods.
49
+ * `Hexx::Name` - The commonly used parser that takes a string and decorates it with methods, returning conventional names (for class, method, gemname, file, path etc.).
50
+ * `$ hexx` - The CLI command to run scaffolders, defined in submodules (see below).
51
+
52
+ All the specific scaffolders are created in their own submodules:
53
+
54
+ * [hexx-domain] - Scaffolder for a new gem with a test suite.
55
+ * [hexx-dependencies] - Scaffolder for the [IoC container], dummy app, and a new dependency from an external module.
56
+ * [hexx-install] - A base generator for tasks, installing a gem inside a host application.
57
+ * [hexx-validators] - Scaffolder for [activemodel] validators.
58
+ * [hexx-services] - Scaffolder for [service objects][service_objects].
59
+ * [hexx-entities] - Scaffolder for [virtus]-based entities.
60
+ * [hexx-values] - Scaffolder for [virtus]-based value objects.
61
+
62
+ There is one special submodule [hexx-suit] that provides shared dev/test environment.
63
+
64
+ [hexx-dependencies]: https://github.com/nepalez/hexx-dependencies
65
+ [hexx-domain]: https://github.com/nepalez/hexx-domain
66
+ [hexx-entities]: https://github.com/nepalez/hexx-entities
67
+ [hexx-install]: https://github.com/nepalez/hexx-install
68
+ [hexx-services]: https://github.com/nepalez/hexx-services
69
+ [hexx-suit]: https://github.com/nepalez/hexx-suit
70
+ [hexx-validators]: https://github.com/nepalez/hexx-validators
71
+ [hexx-values]: https://github.com/nepalez/hexx-values
72
+
73
+ ## Usage
74
+
75
+ The usage of scaffolders is pretty standard.
76
+
77
+ To view all the available options, run from CLI:
78
+
79
+ ```
80
+ hexx -h
81
+ ```
82
+
83
+ Every scaffolder has its own help, available via `-h` option, for example:
84
+
85
+ ```
86
+ hexx service -h
87
+ ```
88
+
89
+ For the usage of [hexx-suit] see [the gem's API][hexx-suit API].
90
+
91
+ [hexx-suit API]: http://www.rubydoc.info/github/nepalez/hexx-suit
92
+
93
+ ## Installation
94
+
95
+ Add this line to your application's Gemfile:
96
+
97
+ ```ruby
98
+ # Gemfile
99
+ group :test, :development do
100
+ gem "hexx"
101
+ end
102
+ ```
103
+
104
+ Then execute:
105
+
106
+ ```
107
+ bundle
108
+ ```
109
+
110
+ Or add it manually:
111
+
112
+ ```
113
+ gem install hexx
114
+ ```
115
+
116
+ ## Compatibility
117
+
118
+ Tested under MRI rubies >= 2.1. Rubies under 2.1 aren't supported.
119
+
120
+ Uses [RSpec] 3.0+ for testing and [hexx-suit] for dev/test tools collection.
121
+
122
+ ## Contributing
123
+
124
+ * Fork the project.
125
+ * Read the [STYLEGUIDE].
126
+ * Make your feature addition or bug fix.
127
+ * Add tests for it. This is important so I don't break it in a
128
+ future version unintentionally.
129
+ * Commit, do not mess with Rakefile or version
130
+ (if you want to have your own version, that is fine but bump version
131
+ in a commit by itself I can ignore when I pull)
132
+ * Send me a pull request. Bonus points for topic branches.
133
+
134
+ [STYLEGUIDE]: file:./config/metrics/STYLEGUIDE
135
+
136
+ ## License
137
+
138
+ See [MIT LICENSE].
data/Rakefile CHANGED
@@ -1,23 +1,17 @@
1
+ # encoding: utf-8
1
2
  begin
2
3
  require "bundler/setup"
3
4
  rescue LoadError
4
5
  puts "You must `gem install bundler` and `bundle install` to run rake tasks"
6
+ exit
5
7
  end
6
8
 
9
+ # Loads bundler tasks
7
10
  Bundler::GemHelper.install_tasks
8
11
 
9
- require "bundler/gem_tasks"
10
- require "rspec/core/rake_task"
12
+ # Loads the Hexx::Suit and its tasks
13
+ require "hexx-suit"
14
+ Hexx::Suit.install_tasks
11
15
 
12
- RSpec::Core::RakeTask.new(:spec)
13
-
14
- task :default do
15
- system "bundle exec rspec spec"
16
- end
17
-
18
- task :check do
19
- system "coveralls report"
20
- system "rubocop"
21
- system "inch --pedantic"
22
- system "metric_fu --no-cane --no-saikuro --no-roodi --no-hotspots --no-stats"
23
- end
16
+ # Sets the Hexx::Suit :test task to default
17
+ task default: "check:coverage"
@@ -0,0 +1,5 @@
1
+ # encoding: utf-8
2
+
3
+ # Adds specific configurations to RSpec for :sandbox and :capture tags
4
+ require_relative "initializers/sandbox"
5
+ require_relative "initializers/capture"
@@ -0,0 +1,19 @@
1
+ # encoding: utf-8
2
+
3
+ # Captures and returns the results of capturing $stdout
4
+ def capture_stdout
5
+ begin
6
+ $stdout = StringIO.new
7
+ yield
8
+ ensure
9
+ result, $stdout = $stdout.string, STDOUT
10
+ end
11
+ result
12
+ end
13
+
14
+ # Captures stdout of specifications with :capture tag
15
+ RSpec.configure do |config|
16
+ config.around :each, :capture do |example|
17
+ capture_stdout { example.run }
18
+ end
19
+ end
@@ -0,0 +1,16 @@
1
+ # encoding: utf-8
2
+
3
+ # Re-creates tmp/sandbox before specs with :sandbox tag
4
+ # Defines specific helpers and matchers for the specifications
5
+ RSpec.configure do |config|
6
+
7
+ config.before :each, :sandbox do
8
+ require_relative "sandbox/helpers"
9
+ require_relative "sandbox/matchers"
10
+ prepare_sandbox
11
+ end
12
+
13
+ config.after :each, :sandbox do
14
+ clear_sandbox
15
+ end
16
+ end
@@ -0,0 +1,38 @@
1
+ # Path to the temporary `tmp/sandbox` folder
2
+ #
3
+ # @return [String]
4
+ def sandbox
5
+ @sandbox ||= File.expand_path "tmp/sandbox"
6
+ end
7
+
8
+ # Clears the sandbox
9
+ #
10
+ # @return [undefined]
11
+ def clear_sandbox
12
+ FileUtils.rm_rf sandbox
13
+ end
14
+
15
+ # Re-creates the sandbox
16
+ #
17
+ # @return [undefined]
18
+ def prepare_sandbox
19
+ clear_sandbox
20
+ FileUtils.mkdir_p sandbox
21
+ end
22
+
23
+ # Runs code in a sandbox
24
+ #
25
+ # @return [undefined]
26
+ def try_in_sandbox
27
+ FileUtils.cd(sandbox) { yield }
28
+ end
29
+
30
+ # Reads file in sandbox and returns its content
31
+ #
32
+ # @return [String]
33
+ # @return [""]
34
+ # when the file is absent
35
+ def read_in_sandbox(filename)
36
+ file = Dir[File.join(sandbox, filename)].first
37
+ file ? File.read(file) : ""
38
+ end
@@ -0,0 +1,19 @@
1
+ # Checks if a file with given name is present in sandbox.
2
+ #
3
+ # @example
4
+ # expect("some_file.rb").to be_present_in_sandbox
5
+ RSpec::Matchers.define :be_present_in_sandbox do
6
+ match do |filename|
7
+ files = Dir[File.join(sandbox, filename)]
8
+ expect(files).to be_any
9
+ end
10
+ end
11
+
12
+ # Checks if a file with given name is absent in sandbox.
13
+ #
14
+ # @example
15
+ # expect("some_file.rb").to be_absent_in_sandbox
16
+ RSpec::Matchers.define_negated_matcher(
17
+ :be_absent_in_sandbox,
18
+ :be_present_in_sandbox
19
+ )
@@ -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.