deconstructable 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: 5952379b5d8b241865bf23ef9b5489a0ea4b4891aa7e8b6a5eaf6c48e26311d9
4
+ data.tar.gz: 1ccac725c212feba2181e8aaeb43439d6374653b275362915f85fad908e46a35
5
+ SHA512:
6
+ metadata.gz: ac3cc004eb2aafcba212a68d488a0b7f1a453a77be633136769551865b4423ec29a9269873fd5ebf18ac554fbc18d201ca2e77cdbdda4cf4d852f948a0980b1b
7
+ data.tar.gz: bd41333c129900c88a9b516c0450a192f6a6a7969261fc6375ee3cf6d8c7fa94ab0af6f64fd89c710c51061c8e5fdcaf014979db8e4fde78366b8df9f8052c94
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/.gitlab-ci.yml ADDED
@@ -0,0 +1,15 @@
1
+ image: "ruby:2.7"
2
+
3
+ before_script:
4
+ - ruby -v
5
+ - which ruby
6
+ - gem install bundler --no-document
7
+ - bundle install --jobs $(nproc) "${FLAGS[@]}"
8
+
9
+ rspec:
10
+ script:
11
+ - bundle exec rspec
12
+
13
+ rubocop:
14
+ script:
15
+ - bundle exec rubocop
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,30 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.7
3
+
4
+ Style/Encoding:
5
+ Enabled: false
6
+
7
+ Layout/LineLength:
8
+ Max: 99
9
+
10
+ Layout/SpaceAroundMethodCallOperator:
11
+ Enabled: true
12
+
13
+ Lint/RaiseException:
14
+ Enabled: true
15
+
16
+ Lint/StructNewOverride:
17
+ Enabled: true
18
+
19
+ Style/ExponentialNotation:
20
+ Enabled: true
21
+
22
+ Style/HashEachMethods:
23
+ Enabled: true
24
+
25
+ Style/HashTransformKeys:
26
+ Enabled: true
27
+
28
+ Style/HashTransformValues:
29
+ Enabled: true
30
+
data/.tool-versions ADDED
@@ -0,0 +1 @@
1
+ ruby 2.7.0
@@ -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 alex.kalderimis@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
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in deconstructable.gemspec
6
+ gemspec
7
+
8
+ gem 'rake', '~> 12.0'
9
+ gem 'rubocop', '~> 0.82.0', require: false
data/Gemfile.lock ADDED
@@ -0,0 +1,52 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ deconstructable (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.0)
10
+ diff-lcs (1.3)
11
+ jaro_winkler (1.5.4)
12
+ parallel (1.19.1)
13
+ parser (2.7.1.2)
14
+ ast (~> 2.4.0)
15
+ rainbow (3.0.0)
16
+ rake (12.3.3)
17
+ rexml (3.2.4)
18
+ rspec (3.9.0)
19
+ rspec-core (~> 3.9.0)
20
+ rspec-expectations (~> 3.9.0)
21
+ rspec-mocks (~> 3.9.0)
22
+ rspec-core (3.9.1)
23
+ rspec-support (~> 3.9.1)
24
+ rspec-expectations (3.9.0)
25
+ diff-lcs (>= 1.2.0, < 2.0)
26
+ rspec-support (~> 3.9.0)
27
+ rspec-mocks (3.9.1)
28
+ diff-lcs (>= 1.2.0, < 2.0)
29
+ rspec-support (~> 3.9.0)
30
+ rspec-support (3.9.2)
31
+ rubocop (0.82.0)
32
+ jaro_winkler (~> 1.5.1)
33
+ parallel (~> 1.10)
34
+ parser (>= 2.7.0.1)
35
+ rainbow (>= 2.2.2, < 4.0)
36
+ rexml
37
+ ruby-progressbar (~> 1.7)
38
+ unicode-display_width (>= 1.4.0, < 2.0)
39
+ ruby-progressbar (1.10.1)
40
+ unicode-display_width (1.7.0)
41
+
42
+ PLATFORMS
43
+ ruby
44
+
45
+ DEPENDENCIES
46
+ deconstructable!
47
+ rake (~> 12.0)
48
+ rspec (~> 3.2)
49
+ rubocop (~> 0.82.0)
50
+
51
+ BUNDLED WITH
52
+ 2.1.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Alex Kalderimis
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,85 @@
1
+ # Deconstructable
2
+
3
+ This gem provides Deconstructable, a mixin module that helps you to support
4
+ pattern-matching over your types.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'deconstructable'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle install
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install deconstructable
21
+
22
+
23
+ ## Usage
24
+
25
+ ```
26
+ class Thing
27
+ include Deconstructable
28
+
29
+ ...
30
+
31
+ # Mark some methods as deconstructable
32
+ deconstructable :x, :y
33
+
34
+ # Shortcut for attr_reader + deconstructable
35
+ attr_deconstructable :readable_and_matchable
36
+
37
+ # Using deconstructable as a method modifier
38
+ deconstructable def foo
39
+ do_the_foo
40
+ end
41
+ end
42
+ ```
43
+
44
+ This class provides a single DSL method `deconstructable` which helps you to mark
45
+ methods and attributes as deconstructable. Deconstructable attributes will be made
46
+ available in pattern matching, e.g.:
47
+
48
+ ```
49
+ thing in Thing(foo:, x: 100, y:)
50
+ ```
51
+
52
+ Classes that include `Deconstructable` gain an implementation of `deconstruct_keys` that permits
53
+ hash-style key based pattern matching. Positional array-style patterns are not supported.
54
+ All deconstructable methods must support being called with no parameters.
55
+
56
+ ## Development
57
+
58
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run
59
+ `rake spec` to run the tests. You can also run `bin/console` for an interactive
60
+ prompt that will allow you to experiment.
61
+
62
+ To install this gem onto your local machine, run `bundle exec rake install`. To
63
+ release a new version, update the version number in `version.rb`, and then run
64
+ `bundle exec rake release`, which will create a git tag for the version, push
65
+ git commits and tags, and push the `.gem` file to
66
+ [rubygems.org](https://rubygems.org).
67
+
68
+ This Gem requires the new pattern matching features introduced in Ruby 2.7.0, so
69
+ we need at least that version. I use `asdf`, and have supplied a suitable
70
+ `.tool-versions` file. You can use this, or any other Ruby version manager.
71
+
72
+ ## Contributing
73
+
74
+ Bug reports and pull requests are welcome on GitLab at
75
+ https://gitlab.com/alexkalderimis/deconstructable. This project is intended to
76
+ be a safe, welcoming space for collaboration, and contributors are expected to
77
+ adhere to the [code of conduct](https://gitlab.com/alexkalderimis/deconstructable/-/blob/master/CODE_OF_CONDUCT.md).
78
+
79
+ ## License
80
+
81
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
82
+
83
+ ## Code of Conduct
84
+
85
+ Everyone interacting in the Deconstructable project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://gitlab.com/alexkalderimis/deconstructable/-/blob/master/CODE_OF_CONDUCT.md).
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/.rubocop.yml ADDED
@@ -0,0 +1,4 @@
1
+ inherit_from: ../.rubocop.yml
2
+
3
+ Style/FrozenStringLiteralComment:
4
+ Enabled: false
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'deconstructable'
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,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/deconstructable/version'
4
+
5
+ SUMMARY = <<~SUMMARY
6
+ Mixin to help implement deconstructable types
7
+ SUMMARY
8
+
9
+ DESCRIPTION = <<~DESC
10
+ This gem provides Deconstructable, a mixin module that helps you to support
11
+ pattern-matching over your types.
12
+
13
+ Usage
14
+ --------
15
+
16
+ ```
17
+ class Thing
18
+ include Deconstructable
19
+
20
+ ...
21
+
22
+ deconstructable :x, :y
23
+
24
+ deconstructable def foo
25
+ do_the_foo
26
+ end
27
+ end
28
+ ```
29
+
30
+ This class provides a single DSL method `deconstructable` which helps you to mark
31
+ methods and attributes as deconstructable. Deconstructable attributes will be made
32
+ available in pattern matching, e.g.:
33
+
34
+ ```
35
+ thing in Thing(foo:, x: 100, y:)
36
+ ```
37
+
38
+ Classes that include `Deconstructable` gain an implementation of `deconstruct_keys` that permits
39
+ hash-style key based pattern matching. Positional array-style patterns are not supported.
40
+ DESC
41
+
42
+ Gem::Specification.new do |s|
43
+ s.name = 'deconstructable'
44
+ s.version = Deconstructable::VERSION
45
+ s.date = '2020-04-07'
46
+ s.summary = SUMMARY
47
+ s.description = DESCRIPTION
48
+ s.authors = ['Alexis Kalderimis']
49
+ s.email = ['alex.kalderimis@gmail.com']
50
+ s.homepage = 'https://rubygems.org/gems/deconstructable'
51
+ s.license = 'MIT'
52
+ s.required_ruby_version = '>= 2.7.0'
53
+
54
+ s.metadata['homepage_uri'] = s.homepage
55
+ s.metadata['source_code_uri'] = 'https://gitlab.com/alexkalderimis/deconstructable'
56
+ s.metadata['changelog_uri'] = 'https://gitlab.com/alexkalderimis/deconstructable/-/blob/master/CHANGELOG.md'
57
+
58
+ s.files = Dir.chdir(File.expand_path(__dir__)) do
59
+ `git ls-files -z`.split("\x0").reject do |f|
60
+ f.match(%r{^(test|spec|features)/})
61
+ end
62
+ end
63
+ s.require_paths = ['lib']
64
+
65
+ s.add_development_dependency 'rspec', '~> 3.2'
66
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Helpers to implement pattern match-able classes
4
+ module Deconstructable
5
+ def self.included(base)
6
+ base.extend ClassMethods
7
+ end
8
+
9
+ # DSL methods made available to the including class:
10
+ module ClassMethods
11
+ # Method names that represent attributes that should be exposed in patterns
12
+ def deconstructable(*keys)
13
+ @deconstructable ||= (superclass&.instance_variable_get(:@deconstructable)&.dup || [])
14
+ @deconstructable.concat(keys)
15
+ end
16
+
17
+ # Sugar defining readable attributes (as per `attr_reader`) that are
18
+ # deconstructable
19
+ def attr_deconstructable(*keys)
20
+ attr_reader(*keys)
21
+ deconstructable(*keys)
22
+ end
23
+ end
24
+
25
+ def deconstruct_keys(keys)
26
+ keys = keys ? (deconstructable & keys) : deconstructable
27
+
28
+ keys.map { |k| [k, send(k)] }.to_h
29
+ end
30
+
31
+ private
32
+
33
+ def deconstructable
34
+ self.class.deconstructable
35
+ end
36
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Deconstructable
4
+ VERSION = '0.1.0'
5
+ end
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: deconstructable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Alexis Kalderimis
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-04-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.2'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.2'
27
+ description: |
28
+ This gem provides Deconstructable, a mixin module that helps you to support
29
+ pattern-matching over your types.
30
+
31
+ Usage
32
+ --------
33
+
34
+ ```
35
+ class Thing
36
+ include Deconstructable
37
+
38
+ ...
39
+
40
+ deconstructable :x, :y
41
+
42
+ deconstructable def foo
43
+ do_the_foo
44
+ end
45
+ end
46
+ ```
47
+
48
+ This class provides a single DSL method `deconstructable` which helps you to mark
49
+ methods and attributes as deconstructable. Deconstructable attributes will be made
50
+ available in pattern matching, e.g.:
51
+
52
+ ```
53
+ thing in Thing(foo:, x: 100, y:)
54
+ ```
55
+
56
+ Classes that include `Deconstructable` gain an implementation of `deconstruct_keys` that permits
57
+ hash-style key based pattern matching. Positional array-style patterns are not supported.
58
+ email:
59
+ - alex.kalderimis@gmail.com
60
+ executables: []
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - ".gitignore"
65
+ - ".gitlab-ci.yml"
66
+ - ".rspec"
67
+ - ".rubocop.yml"
68
+ - ".tool-versions"
69
+ - CODE_OF_CONDUCT.md
70
+ - Gemfile
71
+ - Gemfile.lock
72
+ - LICENSE.txt
73
+ - README.md
74
+ - Rakefile
75
+ - bin/.rubocop.yml
76
+ - bin/console
77
+ - bin/setup
78
+ - deconstructable.gemspec
79
+ - lib/deconstructable.rb
80
+ - lib/deconstructable/version.rb
81
+ homepage: https://rubygems.org/gems/deconstructable
82
+ licenses:
83
+ - MIT
84
+ metadata:
85
+ homepage_uri: https://rubygems.org/gems/deconstructable
86
+ source_code_uri: https://gitlab.com/alexkalderimis/deconstructable
87
+ changelog_uri: https://gitlab.com/alexkalderimis/deconstructable/-/blob/master/CHANGELOG.md
88
+ post_install_message:
89
+ rdoc_options: []
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: 2.7.0
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ requirements: []
103
+ rubygems_version: 3.1.2
104
+ signing_key:
105
+ specification_version: 4
106
+ summary: Mixin to help implement deconstructable types
107
+ test_files: []