openhouse 0.0.1

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
+ SHA1:
3
+ metadata.gz: ee0a6310ebf083c1251740b589f1e9d3930cefeb
4
+ data.tar.gz: 2e51ef43148b2878f38a9570d4282b4d34d11f81
5
+ SHA512:
6
+ metadata.gz: f34c80fc62239c42cdd15c4d56ed20526e4055d7c9980f6125d2c1a736d26022f599be8f3b9c934c15a26d1b469e451e604980f945d97d94eda40c43a97adea0
7
+ data.tar.gz: 70a03ad14931b19a9d9d95b45e6534a37785c890ef781635c1cdff830ed4a38485e17720fca99684d1425ded947f46c7bdc83798c60163abe53c5c46c37d5601
data/.gitignore ADDED
@@ -0,0 +1,50 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ ## Specific to RubyMotion:
17
+ .dat*
18
+ .repl_history
19
+ build/
20
+ *.bridgesupport
21
+ build-iPhoneOS/
22
+ build-iPhoneSimulator/
23
+
24
+ ## Specific to RubyMotion (use of CocoaPods):
25
+ #
26
+ # We recommend against adding the Pods directory to your .gitignore. However
27
+ # you should judge for yourself, the pros and cons are mentioned at:
28
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
29
+ #
30
+ # vendor/Pods/
31
+
32
+ ## Documentation cache and generated files:
33
+ /.yardoc/
34
+ /_yardoc/
35
+ /doc/
36
+ /rdoc/
37
+
38
+ ## Environment normalization:
39
+ /.bundle/
40
+ /vendor/bundle
41
+ /lib/bundler/man/
42
+
43
+ # for a library or gem, you might want to ignore these files since the code is
44
+ # intended to run in multiple environments; otherwise, check them in:
45
+ Gemfile.lock
46
+ .ruby-version
47
+ .ruby-gemset
48
+
49
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50
+ .rvmrc
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 1.9.3
5
+ - 2.0.0
6
+ - 2.1.0
7
+ - 2.2.0
8
+ - 2.3.0
9
+ - 2.4.0
10
+ before_install: gem install bundler -v 1.15.1
data/CHANGELOG.md ADDED
@@ -0,0 +1,14 @@
1
+ # OpenHouse Changelog
2
+
3
+ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning][Semver].
4
+
5
+ ## [Unreleased]
6
+
7
+ * Your contribution here!
8
+
9
+ ## 0.0.1 (2017-06-20)
10
+
11
+ * Initial release
12
+
13
+ [Semver]: http://semver.org
14
+ [Unreleased]: https://github.com/eugeniobruno/openhouse/compare/v0.0.1...HEAD
@@ -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 eugeniobruno@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 [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in openhouse.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Eugenio Bruno
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,69 @@
1
+ # OpenHouse
2
+
3
+ OpenHouse provides a module which simplifies implementing the Visitor design pattern on a type hierarchy.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'openhouse'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install openhouse
20
+
21
+ ## Usage
22
+
23
+ Here is a simple example:
24
+
25
+ ```ruby
26
+ class EmperorPenguin
27
+
28
+ include OpenHouse::Acceptor
29
+
30
+ attr_reader :weight
31
+
32
+ def initialize(weight)
33
+ @weight = weight
34
+ end
35
+
36
+ end
37
+
38
+ class AnimalAnnouncerVisitor
39
+
40
+ def visit_emperor_penguin(emperor_penguin)
41
+ "This is an emperor penguin that weights #{emperor_penguin.weight} kg."
42
+ end
43
+
44
+ end
45
+
46
+ animal = EmperorPenguin.new(42)
47
+ visitor = AnimalAnnouncerVisitor.new
48
+
49
+ animal.accept_visitor(visitor)
50
+ ```
51
+
52
+ An example with a full type hierarchy that shows more features can be found in the test files.
53
+
54
+
55
+ ## Development
56
+
57
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
58
+
59
+ To install this gem onto your local machine, run `bundle exec rake install`.
60
+
61
+ ## Contributing
62
+
63
+ Bug reports and pull requests are welcome on GitHub at https://github.com/eugeniobruno/openhouse. 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.
64
+
65
+
66
+ ## License
67
+
68
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
69
+
data/Rakefile ADDED
@@ -0,0 +1,17 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << 'test'
6
+ t.test_files = FileList['test/**/test_*.rb']
7
+ end
8
+
9
+ task default: :test
10
+
11
+ desc 'Start a REPL session'
12
+ task :console do
13
+ require 'openhouse'
14
+ require 'pry'
15
+ ARGV.clear
16
+ Pry.start
17
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'openhouse'
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,6 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
@@ -0,0 +1,37 @@
1
+ module OpenHouse
2
+ module Acceptor
3
+ def accept_visitor(visitor, *args)
4
+ visitor.public_send("visit_#{own_acceptor_type_id}", self, *args)
5
+ end
6
+
7
+ def accept_visitor_in_ancestry(visitor, *args)
8
+ accept_visitor_in_modules(visitor, self.class.ancestors, *args)
9
+ end
10
+
11
+ private
12
+
13
+ def own_acceptor_type_id
14
+ acceptor_type_id(self.class)
15
+ end
16
+
17
+ def acceptor_type_id(modul)
18
+ if modul.const_defined?(:ACCEPTOR_TYPE_ID, false)
19
+ modul::ACCEPTOR_TYPE_ID
20
+ else
21
+ OpenHouse.simple_inflector.underscored_demodulized(modul.name).to_sym
22
+ end
23
+ end
24
+
25
+ def accept_visitor_in_modules(visitor, modules, *args)
26
+ modules.each do |modul|
27
+ method_name_suffix = acceptor_type_id(modul)
28
+ if visitor.respond_to?("visit_#{method_name_suffix}")
29
+ return visitor.public_send("visit_#{method_name_suffix}", self, *args)
30
+ end
31
+ end
32
+
33
+ error_message = "undefined method 'visit_[acceptor_type_id]' for #{visitor.class} for any of these modules: #{modules}"
34
+ raise NoMethodError, error_message
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,22 @@
1
+ module OpenHouse
2
+ class SimpleInflector
3
+ def demodulized(module_name)
4
+ module_name.split('::').last
5
+ end
6
+
7
+ def underscored(module_name)
8
+ return module_name.downcase if module_name.upcase == module_name
9
+
10
+ ret = module_name # MyModuleName ABCName
11
+ .gsub(/([A-Z])/, '_\1'.freeze) # _My_Module_Name _A_B_C_Name
12
+ .gsub(/([A-Z])_([A-Z])_/, '\1\2'.freeze) # _ABC_Name
13
+ .downcase # _my_module_name _abc_name
14
+
15
+ ret.start_with?('_') ? ret[1..-1] : ret
16
+ end
17
+
18
+ def underscored_demodulized(module_name)
19
+ underscored(demodulized(module_name))
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,3 @@
1
+ module OpenHouse
2
+ VERSION = '0.0.1'.freeze
3
+ end
data/lib/openhouse.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'openhouse/version'
2
+
3
+ require 'openhouse/simple_inflector'
4
+ require 'openhouse/acceptor'
5
+
6
+ module OpenHouse
7
+ def self.simple_inflector
8
+ @simple_inflector ||= SimpleInflector.new
9
+ end
10
+ end
data/openhouse.gemspec ADDED
@@ -0,0 +1,42 @@
1
+ # coding: utf-8
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'openhouse/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'openhouse'
9
+ spec.version = OpenHouse::VERSION
10
+ spec.date = '2017-06-20'
11
+ spec.authors = ['Eugenio Bruno']
12
+ spec.email = ['eugeniobruno@gmail.com']
13
+
14
+ spec.summary = 'OpenHouse simplifies implementing the Visitor design pattern.'
15
+ spec.homepage = 'https://github.com/eugeniobruno/openhouse'
16
+ spec.license = 'MIT'
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
19
+ f.match(%r{^(test|spec|features)/})
20
+ end
21
+ spec.bindir = 'bin'
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
24
+ spec.require_paths = ['lib']
25
+ spec.extra_rdoc_files = %w[LICENSE.txt README.md CODE_OF_CONDUCT.md CHANGELOG.md]
26
+
27
+ spec.required_ruby_version = '>= 1.9.3'
28
+
29
+ spec.add_development_dependency 'bundler', '~> 1.15'
30
+ spec.add_development_dependency 'rake', '~> 10.0'
31
+ spec.add_development_dependency 'minitest', '~> 5.0'
32
+ spec.add_development_dependency 'minitest-bender', '~> 0.0'
33
+ spec.add_development_dependency 'simplecov', '~> 0.14'
34
+ spec.add_development_dependency 'coveralls', '~> 0.8'
35
+ spec.add_development_dependency 'pry-byebug', '~> 3.4'
36
+
37
+ if RUBY_VERSION < '2'
38
+ spec.add_development_dependency 'term-ansicolor', '~> 1.3.0'
39
+ spec.add_development_dependency 'tins', '~> 1.6.0'
40
+ spec.add_development_dependency 'json', '~> 1.8'
41
+ end
42
+ end
metadata ADDED
@@ -0,0 +1,161 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: openhouse
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Eugenio Bruno
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-06-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.15'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest-bender
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.14'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.14'
83
+ - !ruby/object:Gem::Dependency
84
+ name: coveralls
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.8'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.8'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry-byebug
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.4'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.4'
111
+ description:
112
+ email:
113
+ - eugeniobruno@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files:
117
+ - LICENSE.txt
118
+ - README.md
119
+ - CODE_OF_CONDUCT.md
120
+ - CHANGELOG.md
121
+ files:
122
+ - ".gitignore"
123
+ - ".travis.yml"
124
+ - CHANGELOG.md
125
+ - CODE_OF_CONDUCT.md
126
+ - Gemfile
127
+ - LICENSE.txt
128
+ - README.md
129
+ - Rakefile
130
+ - bin/console
131
+ - bin/setup
132
+ - lib/openhouse.rb
133
+ - lib/openhouse/acceptor.rb
134
+ - lib/openhouse/simple_inflector.rb
135
+ - lib/openhouse/version.rb
136
+ - openhouse.gemspec
137
+ homepage: https://github.com/eugeniobruno/openhouse
138
+ licenses:
139
+ - MIT
140
+ metadata: {}
141
+ post_install_message:
142
+ rdoc_options: []
143
+ require_paths:
144
+ - lib
145
+ required_ruby_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: 1.9.3
150
+ required_rubygems_version: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ requirements: []
156
+ rubyforge_project:
157
+ rubygems_version: 2.5.1
158
+ signing_key:
159
+ specification_version: 4
160
+ summary: OpenHouse simplifies implementing the Visitor design pattern.
161
+ test_files: []