weakest_link 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: db58be9c24f35a0e84ebb943cb5bbe0a94cf190d4c3e107b9db0e3616d1c70d4
4
+ data.tar.gz: e8566832955c3e4804f93364c2e967332acbb3c199bcf4382263e77634d130ec
5
+ SHA512:
6
+ metadata.gz: 74cb898bff54c71e9914ab61be12f9bbe0718d8f4425e8148e9f7e808cdca68cc22a22dc62822e2dfc0869ecd39914773bea0927f6c8f84cb476f47e30eb896a
7
+ data.tar.gz: 5e6489398f27c7507051cde15c9d07d93c1d70dabce88bcbd0b3780bfec59d872459a25d2036c6b29acbb64639d569b957e2e785e099c47dcede80fa3f65bb80
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in weakest_link.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Joseph Johansen
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,58 @@
1
+ # WeakestLink
2
+
3
+ Weakest link is a very lightweight gem which allows you to safely chain multiple methods together, without having to
4
+ repeat the safe navigation operator for each call.
5
+
6
+ ### Example
7
+
8
+ #### Standard ruby
9
+ ```ruby
10
+ my_array = rand > 0.5 ? [] : ['foo']
11
+ my_array.first&.length&.split&.join(" ")&.reverse # etc
12
+ ```
13
+
14
+ #### Weakest Link
15
+ ```ruby
16
+ require 'weakest_link'
17
+ my_array = rand > 0.5 ? [] : ['foo']
18
+ # start and end the sequence of safe calls with :£
19
+ my_array.£.first.length.split.join(" ").reverse.£ # etc
20
+ ```
21
+
22
+ If `£` is not a convenient character, or you would prefer something else, you can also configure other aliases:
23
+
24
+ ```ruby
25
+ WeakestLink.aliases = %i[€ foo]
26
+ my_array.€.first.length.split.join(" ").reverse.€ # etc
27
+ my_array.foo.first.length.split.join(" ").reverse.foo # etc
28
+ ```
29
+
30
+ ## Installation
31
+
32
+ Add this line to your application's Gemfile:
33
+
34
+ ```ruby
35
+ gem 'weakest_link'
36
+ ```
37
+
38
+ And then execute:
39
+
40
+ $ bundle install
41
+
42
+ Or install it yourself as:
43
+
44
+ $ gem install weakest_link
45
+
46
+ ## Development
47
+
48
+ 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.
49
+
50
+ 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
51
+
52
+ ## Contributing
53
+
54
+ Bug reports and pull requests are welcome on GitHub at https://github.com/johansenja/weakest_link.
55
+
56
+ ## License
57
+
58
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "weakest_link"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ class NilClass
4
+ class << self
5
+ attr_accessor :__method_chaining__
6
+ end
7
+
8
+ def method_missing meth, *args, **kw, &blk
9
+ super unless self.class.__method_chaining__
10
+ end
11
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Object
4
+ def £
5
+ NilClass.__method_chaining__ = !NilClass.__method_chaining__
6
+ self
7
+ end
8
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "weakest_link/version"
4
+ require_relative "core_ext/nil"
5
+ require_relative "core_ext/object"
6
+
7
+ module WeakestLink
8
+ def self.aliases= others
9
+ others.each do |m|
10
+ Object.alias_method m, :£
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WeakestLink
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/weakest_link/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "weakest_link"
7
+ spec.version = WeakestLink::VERSION
8
+ spec.authors = ["Joseph Johansen"]
9
+ spec.email = ["joe@stotles.com"]
10
+
11
+ spec.summary = "Safe navigator method chaining without the repetition"
12
+ spec.description = "Chain multiple methods together safely without having to repeat the safe navigation operator for each call"
13
+ spec.homepage = "https://github.com/johansenja/weakest_link"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
16
+
17
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
18
+
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+ spec.metadata["source_code_uri"] = "https://github.com/johansenja/weakest_link"
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
25
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
26
+ end
27
+ spec.require_paths = ["lib"]
28
+
29
+ # Uncomment to register a new dependency of your gem
30
+ # spec.add_dependency "example-gem", "~> 1.0"
31
+
32
+ # For more information and examples about making a new gem, checkout our
33
+ # guide at: https://bundler.io/guides/creating_gem.html
34
+ end
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: weakest_link
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Joseph Johansen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-06-14 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Chain multiple methods together safely without having to repeat the safe
14
+ navigation operator for each call
15
+ email:
16
+ - joe@stotles.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".gitignore"
22
+ - ".rspec"
23
+ - Gemfile
24
+ - LICENSE.txt
25
+ - README.md
26
+ - Rakefile
27
+ - bin/console
28
+ - bin/setup
29
+ - lib/core_ext/nil.rb
30
+ - lib/core_ext/object.rb
31
+ - lib/weakest_link.rb
32
+ - lib/weakest_link/version.rb
33
+ - weakest_link.gemspec
34
+ homepage: https://github.com/johansenja/weakest_link
35
+ licenses:
36
+ - MIT
37
+ metadata:
38
+ allowed_push_host: https://rubygems.org
39
+ homepage_uri: https://github.com/johansenja/weakest_link
40
+ source_code_uri: https://github.com/johansenja/weakest_link
41
+ post_install_message:
42
+ rdoc_options: []
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 2.4.0
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ requirements: []
56
+ rubygems_version: 3.1.2
57
+ signing_key:
58
+ specification_version: 4
59
+ summary: Safe navigator method chaining without the repetition
60
+ test_files: []