jgomo3-func 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0b6cfecdff107f74516b252a00057ff4490239b21d3ca56eead0e75d1448ffef
4
+ data.tar.gz: a6e22e6ad37289340d286dd27e297d5a0a1c259f216a7257005084995d7f79f7
5
+ SHA512:
6
+ metadata.gz: 8019ec224ad628cb8a3696a2e42e1b09a0fbffdf12f7a54f33d0157a425beb04028d7262c78361639016201c741a30d6332376b7470a24034a9ebf1bde6c91c0
7
+ data.tar.gz: 721de13bbbcde4d5fadeac3e05109718e6c1ef65e751df13ea4369005ea0903da9181908c08a0599e3a84fe6b9ce98185372df7846d2b8457f1d46f2ed37d69f
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/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.6
6
+ before_install: gem install bundler -v 2.1.4
data/CHANGELOG.md ADDED
@@ -0,0 +1,18 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
4
+ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
5
+
6
+ ## 0.1.0 - 2022-11-15
7
+ ### Added
8
+ - Object extensions
9
+ - then_if
10
+ - process the receiver with the given block if condition is true
11
+ - unless_if
12
+ - complement of `then_if`
13
+ - complement
14
+ - produce a proc which is the logical complement of the receiver
15
+ - constantly
16
+ - produce a proc which always returns the receiver
17
+
18
+ ---
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at jgomo3@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in jgomo3-func.gemspec
4
+ gemspec
5
+
6
+ gem 'codelog'
7
+ gem "rake", "~> 12.0"
8
+ gem "rspec", "~> 3.0"
9
+ gem 'yard'
data/Gemfile.lock ADDED
@@ -0,0 +1,43 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ jgomo3-func (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ codelog (0.8.0)
10
+ thor (~> 0.19)
11
+ diff-lcs (1.5.0)
12
+ rake (12.3.3)
13
+ rspec (3.12.0)
14
+ rspec-core (~> 3.12.0)
15
+ rspec-expectations (~> 3.12.0)
16
+ rspec-mocks (~> 3.12.0)
17
+ rspec-core (3.12.0)
18
+ rspec-support (~> 3.12.0)
19
+ rspec-expectations (3.12.0)
20
+ diff-lcs (>= 1.2.0, < 2.0)
21
+ rspec-support (~> 3.12.0)
22
+ rspec-mocks (3.12.0)
23
+ diff-lcs (>= 1.2.0, < 2.0)
24
+ rspec-support (~> 3.12.0)
25
+ rspec-support (3.12.0)
26
+ thor (0.20.3)
27
+ webrick (1.7.0)
28
+ yard (0.9.28)
29
+ webrick (~> 1.7.0)
30
+
31
+ PLATFORMS
32
+ ruby
33
+ x86_64-linux
34
+
35
+ DEPENDENCIES
36
+ codelog
37
+ jgomo3-func!
38
+ rake (~> 12.0)
39
+ rspec (~> 3.0)
40
+ yard
41
+
42
+ BUNDLED WITH
43
+ 2.3.7
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Jesús Gómez
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,91 @@
1
+ # Jgomo3::Func
2
+
3
+ By requiring this Gem, some extensions will be applied to Ruby core
4
+ classes (similar to what Activesupport does).
5
+
6
+ The extensions is a collection of methods I find useful for any
7
+ project. This is a quick list:
8
+
9
+ ## `then_if` and `then_unless`
10
+
11
+ Whenever you use `then` guarded by some simple ternary logic, ej:
12
+
13
+ ```
14
+ number.then { _1.positive? ? _1 * 1000 : _1 }
15
+ ```
16
+
17
+ you can use `then_if` (or `then_unless`):
18
+
19
+ ```
20
+ number.then_if(:positive?) { _1 * 1000 }
21
+ number.then_if(->(x){ x.positive? }) { _1 * 1000 }
22
+ ```
23
+
24
+ `then_if` and `then_unless` receive an argument which will be used as
25
+ a function, first by verifying it responds to `call`, lastly, by
26
+ trying to convert it to a **Proc**. That's why this method works with
27
+ **Symbols**, because they respond to
28
+ [to_proc](https://devdocs.io/ruby~2.7/symbol#method-i-to_proc).
29
+
30
+ ## `complement`
31
+
32
+ Generates a Proc that negates the object if it would have been used as
33
+ a function.
34
+
35
+ ```
36
+ negative = :positive?.complement
37
+ negative.call(1) # => false
38
+ negative.call(-1) # => true
39
+ ```
40
+
41
+ `complement` will use the receiver as a function first by verifying it
42
+ responds to `call` it, lastly, by trying to convert it to a
43
+ **Proc**. That's why this method works with **Symbols**, because they
44
+ respond to
45
+ [to_proc](https://devdocs.io/ruby~2.7/symbol#method-i-to_proc).
46
+
47
+ ## `constantly`
48
+ Generates a Proc that always returns it's receiver.
49
+
50
+ ```
51
+ constantly_true = true.constantly
52
+ constantly_true.call(12345) # => true
53
+ constantly_true.call('Hola') # => true
54
+ constantly_true.call(nil) # => true
55
+ constantly_true.call(Object.new) # => true
56
+ ```
57
+
58
+ ## Installation
59
+
60
+ Add this line to your application's Gemfile:
61
+
62
+ ```ruby
63
+ gem 'jgomo3-func'
64
+ ```
65
+
66
+ And then execute:
67
+
68
+ $ bundle install
69
+
70
+ Or install it yourself as:
71
+
72
+ $ gem install jgomo3-func
73
+
74
+ ## Development
75
+
76
+ 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.
77
+
78
+ 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).
79
+
80
+ ## Contributing
81
+
82
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/jgomo3-func. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/jgomo3-func/blob/master/CODE_OF_CONDUCT.md).
83
+
84
+
85
+ ## License
86
+
87
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
88
+
89
+ ## Code of Conduct
90
+
91
+ Everyone interacting in the Jgomo3::Func project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/jgomo3-func/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "jgomo3/func"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ 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,16 @@
1
+ # Changelog Header -------------------------------------------------
2
+
3
+ header_textfile: changelogs/header.txt
4
+ default_changelog_filename: CHANGELOG.md
5
+
6
+ # Tag formatting ---------------------------------------------------
7
+
8
+ version_prefix: ""
9
+ version_suffix: ""
10
+ date_prefix: ""
11
+
12
+ # Date formatting --------------------------------------------------
13
+
14
+ show_date: true
15
+ date_input_format: "%Y-%m-%d"
16
+ date_output_format: "%Y-%m-%d"
@@ -0,0 +1,4 @@
1
+ All notable changes to this project will be documented in this file.
2
+ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
3
+ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
4
+
File without changes
@@ -0,0 +1,13 @@
1
+ ## 0.1.0 - 2022-11-15
2
+ ### Added
3
+ - Object extensions
4
+ - then_if
5
+ - process the receiver with the given block if condition is true
6
+ - unless_if
7
+ - complement of `then_if`
8
+ - complement
9
+ - produce a proc which is the logical complement of the receiver
10
+ - constantly
11
+ - produce a proc which always returns the receiver
12
+
13
+ ---
@@ -0,0 +1,20 @@
1
+ "Added":
2
+ - New features implemented
3
+
4
+ "Changed":
5
+ - Changes to existing feature
6
+
7
+ "Deprecated":
8
+ - Features that are soon to be removed
9
+
10
+ "Removed":
11
+ - Features that were removed
12
+
13
+ "Fixed":
14
+ - Changes to broken code
15
+
16
+ "Security":
17
+ - Changes that fix vulnerabilities
18
+
19
+ "Deploy notes":
20
+ - Changes that should impact the deploy process and what should be made before it
File without changes
@@ -0,0 +1,29 @@
1
+ require_relative 'lib/jgomo3/func/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "jgomo3-func"
5
+ spec.version = Jgomo3::Func::VERSION
6
+ spec.authors = ["Jesús Gómez"]
7
+ spec.email = ["jgomo3@gmail.com"]
8
+
9
+ spec.summary = 'Library of functions I find useful enough to be included always'
10
+ # spec.description = %q{TODO: Write a longer description or delete this line.}
11
+ spec.homepage = 'https://github.com/jgomo3/jgomo3-func'
12
+ spec.license = "MIT"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
+
15
+ # spec.metadata["allowed_push_host"] = "http://rubygems.org"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = 'https://github.com/jgomo3/jgomo3-func'
19
+ spec.metadata["changelog_uri"] = 'https://github.com/jgomo3/jgomo3-func/CHANGELOG.md'
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ end
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+ end
@@ -0,0 +1,58 @@
1
+ class Object
2
+
3
+ # Returns a Proc which always return the given object
4
+ #
5
+ # constantly_true = true.constantly
6
+ # constantly_true.call(1234) => true
7
+ # constantly_true.call(nil) => true
8
+ # constantly_true.call('HOLA') => true
9
+ def constantly
10
+ Proc.new { self }
11
+ end
12
+
13
+ # Returns a Proc which negates the result of calling the argumented
14
+ # callable object.
15
+ #
16
+ # :positive?.complement.call(1) => false
17
+ # :nil?.complement.call(nil) => false
18
+ def complement
19
+ callable = case
20
+ when respond_to?(:call)
21
+ self
22
+ else
23
+ self.to_proc
24
+ end
25
+ ->(*args, **kwargs, &blk) { !callable.call(*args, **kwargs, &blk) }
26
+ rescue NoMethodError => error
27
+ case error.name
28
+ when :to_proc
29
+ raise ArgumentError, "Object is not 'Callable' so it can't have a complement function", caller
30
+ else
31
+ raise
32
+ end
33
+ end
34
+
35
+ # Applies the given block to the object if the condition applied on
36
+ # it holds true. If not, it defaults to the object as if `then_if`
37
+ # was not called.
38
+ #
39
+ # +1.then_if(:positive?) { _1 * 1000 } => 1_000
40
+ # -1.then_if(:positive?) { _1 * 1000 } => -1
41
+ def then_if(condition)
42
+ if condition.to_proc.call(self)
43
+ yield self
44
+ else
45
+ self
46
+ end
47
+ end
48
+
49
+ # Applies the given block to the object if the condition applied on
50
+ # it doesn't hold true. If not, it defaults to the object as if
51
+ # `then_unless` was not called.
52
+ #
53
+ # +1.then_if(:positive?) { _1 * 1000 } => 1_000
54
+ # -1.then_if(:positive?) { _1 * 1000 } => -1
55
+ def then_unless(condition, &block)
56
+ then_if(condition.complement, &block)
57
+ end
58
+ end
@@ -0,0 +1,5 @@
1
+ module Jgomo3
2
+ module Func
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,8 @@
1
+ require "jgomo3/func/version"
2
+ require "jgomo3/func/core_ext/object"
3
+
4
+ module Jgomo3
5
+ module Func
6
+ class Error < StandardError; end
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jgomo3-func
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jesús Gómez
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-11-15 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ - jgomo3@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".gitignore"
21
+ - ".rspec"
22
+ - ".travis.yml"
23
+ - CHANGELOG.md
24
+ - CODE_OF_CONDUCT.md
25
+ - Gemfile
26
+ - Gemfile.lock
27
+ - LICENSE.txt
28
+ - README.md
29
+ - Rakefile
30
+ - bin/console
31
+ - bin/setup
32
+ - changelogs/codelog.yml
33
+ - changelogs/header.txt
34
+ - changelogs/releases/.gitkeep
35
+ - changelogs/releases/0.1.0.md
36
+ - changelogs/template.yml
37
+ - changelogs/unreleased/.gitkeep
38
+ - jgomo3-func.gemspec
39
+ - lib/jgomo3/func.rb
40
+ - lib/jgomo3/func/core_ext/object.rb
41
+ - lib/jgomo3/func/version.rb
42
+ homepage: https://github.com/jgomo3/jgomo3-func
43
+ licenses:
44
+ - MIT
45
+ metadata:
46
+ homepage_uri: https://github.com/jgomo3/jgomo3-func
47
+ source_code_uri: https://github.com/jgomo3/jgomo3-func
48
+ changelog_uri: https://github.com/jgomo3/jgomo3-func/CHANGELOG.md
49
+ post_install_message:
50
+ rdoc_options: []
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: 2.3.0
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ requirements: []
64
+ rubygems_version: 3.3.7
65
+ signing_key:
66
+ specification_version: 4
67
+ summary: Library of functions I find useful enough to be included always
68
+ test_files: []