-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from gangelo/development
Refactors
- Loading branch information
Showing
11 changed files
with
344 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
exclude_paths: | ||
- vendor | ||
- spec | ||
detectors: | ||
# TooManyInstanceVariables: | ||
# exclude: | ||
# - "Class1" | ||
# - "Class2" | ||
# private methods do not have to depend on instance state | ||
# https://github.com/troessner/reek/blob/master/docs/Utility-Function.md | ||
UtilityFunction: | ||
public_methods_only: true | ||
# Check for variable name that doesn't communicate its intent well enough | ||
# https://github.com/troessner/reek/blob/master/docs/Uncommunicative-Variable-Name.md | ||
UncommunicativeVariableName: | ||
accept: | ||
- /^_$/ | ||
- /^e$/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,198 @@ | ||
# The behavior of RuboCop can be controlled via the .rubocop.yml | ||
# configuration file. It makes it possible to enable/disable | ||
# certain cops (checks) and to alter their behavior if they accept | ||
# any parameters. The file can be placed either in your home | ||
# directory or in some project directory. | ||
# | ||
# RuboCop will start looking for the configuration file in the directory | ||
# where the inspected file is and continue its way up to the root directory. | ||
# | ||
# See https://docs.rubocop.org/rubocop/configuration | ||
require: | ||
- rubocop-performance | ||
- rubocop-rspec | ||
|
||
AllCops: | ||
TargetRubyVersion: 3.0.1 | ||
NewCops: enable | ||
Exclude: | ||
- '.git/**/*' | ||
- '.idea/**/*' | ||
- 'init/*' | ||
- 'Rakefile' | ||
- '*.gemspec' | ||
- 'spec/**/*' | ||
- 'vendor/**/*' | ||
- 'scratch.rb' | ||
|
||
# Align the elements of a hash literal if they span more than one line. | ||
Layout/HashAlignment: | ||
EnforcedLastArgumentHashStyle: always_ignore | ||
|
||
# Alignment of parameters in multi-line method definition. | ||
# The `with_fixed_indentation` style aligns the following lines with one | ||
# level of indentation relative to the start of the line with the method | ||
# definition. | ||
# | ||
# def my_method(a, | ||
# b) | ||
Layout/ParameterAlignment: | ||
EnforcedStyle: with_fixed_indentation | ||
|
||
# Alignment of parameters in multi-line method call. | ||
# The `with_fixed_indentation` style aligns the following lines with one | ||
# level of indentation relative to the start of the line with the method call. | ||
# | ||
# my_method(a, | ||
# b) | ||
Layout/ArgumentAlignment: | ||
EnforcedStyle: with_fixed_indentation | ||
|
||
# a = case n | ||
# when 0 | ||
# x * 2 | ||
# else | ||
# y / 3 | ||
# end | ||
Layout/CaseIndentation: | ||
EnforcedStyle: end | ||
|
||
# Enforces a configured order of definitions within a class body | ||
Layout/ClassStructure: | ||
Enabled: true | ||
|
||
# Align `end` with the matching keyword or starting expression except for | ||
# assignments, where it should be aligned with the LHS. | ||
Layout/EndAlignment: | ||
EnforcedStyleAlignWith: variable | ||
AutoCorrect: true | ||
|
||
# The `consistent` style enforces that the first element in an array | ||
# literal where the opening bracket and the first element are on | ||
# seprate lines is indented the same as an array literal which is not | ||
# defined inside a method call. | ||
Layout/FirstArrayElementIndentation: | ||
EnforcedStyle: consistent | ||
|
||
# The `consistent` style enforces that the first key in a hash | ||
# literal where the opening brace and the first key are on | ||
# seprate lines is indented the same as a hash literal which is not | ||
# defined inside a method call. | ||
Layout/FirstHashElementIndentation: | ||
EnforcedStyle: consistent | ||
|
||
# Indent multi-line methods instead of aligning with periods | ||
Layout/MultilineMethodCallIndentation: | ||
EnforcedStyle: indented | ||
|
||
# Allow `debug` in tasks for now | ||
Lint/Debugger: | ||
Exclude: | ||
- 'RakeFile' | ||
|
||
# A calculated magnitude based on number of assignments, branches, and | ||
# conditions. | ||
# NOTE: This is temporarily disabled until we can eliminate existing Rubocop | ||
# complaints | ||
Metrics/AbcSize: | ||
Enabled: false | ||
|
||
# Avoid long blocks with many lines. | ||
Metrics/BlockLength: | ||
Exclude: | ||
- 'RakeFile' | ||
- 'db/seeds.rb' | ||
- 'spec/**/*.rb' | ||
|
||
# Avoid classes longer than 100 lines of code. | ||
# NOTE: This is temporarily disabled until we can eliminate existing Rubocop | ||
# complaints | ||
Metrics/ClassLength: | ||
Max: 200 | ||
Exclude: | ||
- 'spec/**/*.rb' | ||
|
||
# A complexity metric that is strongly correlated to the number of test cases | ||
# needed to validate a method. | ||
Metrics/CyclomaticComplexity: | ||
Max: 9 | ||
|
||
# Limit lines to 80 characters | ||
Layout/LineLength: | ||
Exclude: | ||
- 'RakeFile' | ||
- 'spec/**/*.rb' | ||
|
||
# Avoid methods longer than 15 lines of code. | ||
Metrics/MethodLength: | ||
Max: 20 | ||
IgnoredMethods: | ||
- swagger_path | ||
- operation | ||
|
||
|
||
# A complexity metric geared towards measuring complexity for a human reader. | ||
Metrics/PerceivedComplexity: | ||
Max: 10 | ||
|
||
# Naming/FileName: | ||
# Exclude: | ||
# - 'lib/file.rb' | ||
|
||
# Allow `downcase == ` instead of forcing `casecmp` | ||
Performance/Casecmp: | ||
Enabled: false | ||
|
||
# Require children definitions to be nested or compact in classes and modules | ||
Style/ClassAndModuleChildren: | ||
Enabled: false | ||
|
||
# Document classes and non-namespace modules. | ||
# (Disabled for now, may revisit later) | ||
Style/Documentation: | ||
Enabled: false | ||
|
||
# Checks the formatting of empty method definitions. | ||
Style/EmptyMethod: | ||
EnforcedStyle: expanded | ||
|
||
# Add the frozen_string_literal comment to the top of files to help transition | ||
# to frozen string literals by default. | ||
Style/FrozenStringLiteralComment: | ||
EnforcedStyle: always | ||
|
||
# Check for conditionals that can be replaced with guard clauses | ||
Style/GuardClause: | ||
Enabled: false | ||
|
||
Style/MixinUsage: | ||
Exclude: | ||
- 'RakeFile' | ||
|
||
# Avoid multi-line method signatures. | ||
Style/MultilineMethodSignature: | ||
Enabled: true | ||
|
||
# Don't use option hashes when you can use keyword arguments. | ||
Style/OptionHash: | ||
Enabled: true | ||
|
||
# Use return instead of return nil. | ||
Style/ReturnNil: | ||
Enabled: true | ||
|
||
# Allow code like `return x, y` as it's occasionally handy. | ||
Style/RedundantReturn: | ||
AllowMultipleReturnValues: true | ||
|
||
# Prefer symbols instead of strings as hash keys. | ||
Style/StringHashKeys: | ||
Enabled: true | ||
|
||
# Checks if configured preferred methods are used over non-preferred. | ||
Style/StringMethods: | ||
Enabled: true | ||
|
||
# Checks for use of parentheses around ternary conditions. | ||
Style/TernaryParentheses: | ||
EnforcedStyle: require_parentheses_when_complex |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
source "https://rubygems.org" | ||
# frozen_string_literal: true | ||
|
||
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } | ||
source 'https://rubygems.org' | ||
|
||
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" } | ||
|
||
# Specify your gem's dependencies in immutable_struct_ex.gemspec | ||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,85 @@ | ||
# ImmutableStructEx | ||
|
||
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/immutable_struct_ex`. To experiment with that code, run `bin/console` for an interactive prompt. | ||
|
||
TODO: Delete this and the text above, and describe your gem | ||
|
||
## Installation | ||
|
||
Add this line to your application's Gemfile: | ||
|
||
```ruby | ||
gem 'immutable_struct_ex' | ||
``` | ||
|
||
And then execute: | ||
|
||
$ bundle | ||
|
||
Or install it yourself as: | ||
|
||
$ gem install immutable_struct_ex | ||
|
||
## Usage | ||
|
||
TODO: Write usage instructions here | ||
|
||
## Development | ||
|
||
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. | ||
|
||
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). | ||
|
||
## Contributing | ||
|
||
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/immutable_struct_ex. 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. | ||
|
||
## License | ||
|
||
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). | ||
|
||
## Code of Conduct | ||
|
||
Everyone interacting in the ImmutableStructEx project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/immutable_struct_ex/blob/master/CODE_OF_CONDUCT.md). | ||
# ImmutableStructEx | ||
|
||
_ImmutableStructEx_ is yet another immutable struct. What makes ImmutableStructEx different, is that it allows you to create immutable structs in one step _by default_. In other words, other immutable struct gems force you to first define the struct, then instantiate the struct object; or, define the struct and instantiate the struct object via chaining. For example: | ||
|
||
## Other Immutable Structs | ||
|
||
```ruby | ||
# Two steps... | ||
some_immutable_struct = SomeImmutableStruct.new(:first, :last, :phone) | ||
some_immutable_struct.new(first: 'John', last: 'Doe', phone: '(201) 230-7281') | ||
|
||
# Chaining... | ||
some_immutable_struct = SomeImmutableStruct.new(:first, :last, :phone) | ||
.new(first: 'John', last: 'Doe', phone: '(201) 230-7281') | ||
``` | ||
|
||
## ImmutableStructEx | ||
ImmutableStructEx allows you do this in one step: | ||
|
||
```ruby | ||
immutable_struct_ex = ImmutableStructEx.new(first: 'John', last: 'Doe', phone: '(201) 230-7281') | ||
immutable_struct_ex.first | ||
#=> 'John' | ||
immutable_struct_ex[:first] | ||
#=> 'John' | ||
immutable_struct_ex.last | ||
#=> 'Doe' | ||
immutable_struct_ex.phone | ||
#=> '(201) 230-7281' | ||
``` | ||
### Immutable | ||
Like other immutable structs, ImmutableStructEx also removes methods that change the state of the object: | ||
```ruby | ||
immutable_struct_ex.first = 'Joe' | ||
#=> NoMethodError: undefined method `first='... | ||
immutable_struct_ex[:first] = 'Joe' | ||
#=> NoMethodError: undefined method `[]='... | ||
``` | ||
|
||
### Blocks | ||
Also, not unlike other immutable structs, ImmutableStructEx also allows you to pass a block: | ||
```ruby | ||
# With a block | ||
immutable_struct_ex = ImmutableStructEx.new(first: 'John', last: 'Doe', phone: '(201) 230-7281') do | ||
def john? | ||
first == 'John' | ||
end | ||
end | ||
immutable_struct_ex.john? | ||
#=> true | ||
``` | ||
|
||
## Installation | ||
|
||
Add this line to your application's Gemfile: | ||
|
||
```ruby | ||
gem 'immutable_struct_ex' | ||
``` | ||
|
||
And then execute: | ||
|
||
$ bundle | ||
|
||
Or install it yourself as: | ||
|
||
$ gem install immutable_struct_ex | ||
|
||
## Development | ||
|
||
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. | ||
|
||
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). | ||
|
||
## Contributing | ||
|
||
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/immutable_struct_ex. 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. | ||
|
||
## License | ||
|
||
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). | ||
|
||
## Code of Conduct | ||
|
||
Everyone interacting in the ImmutableStructEx project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/immutable_struct_ex/blob/master/CODE_OF_CONDUCT.md). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
require "bundler/gem_tasks" | ||
require "rspec/core/rake_task" | ||
# frozen_string_literal: true | ||
|
||
require 'bundler/gem_tasks' | ||
require 'rspec/core/rake_task' | ||
|
||
RSpec::Core::RakeTask.new(:spec) | ||
|
||
task :default => :spec | ||
task default: :spec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.