boring_presenters 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 +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +35 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/boring.gemspec +26 -0
- data/lib/boring/exceptions.rb +0 -0
- data/lib/boring/presenter.rb +150 -0
- data/lib/boring/version.rb +3 -0
- data/lib/boring.rb +2 -0
- metadata +103 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9663b7244fabad34f7b95cdb5ff6c8894ded0632
|
4
|
+
data.tar.gz: 915e1ff891f18232161e47784041d04a7d5a3625
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 39b4c0830ca7e3a94fc668b87c033d652370078294310c3e16746e10655310a01304582057d6f048a78f43bf8cb842778e7060fc4358df1c3f511347588f6402
|
7
|
+
data.tar.gz: 1791d3606fafa05d3bb414221c17c0271bbc6f92e0dfa9eae101a3b8f603bacdc8b5c6d789300452804d0371dd5b47af008615838d7bf47a4036e9aab994542b
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
boring (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.3)
|
10
|
+
rake (10.5.0)
|
11
|
+
rspec (3.7.0)
|
12
|
+
rspec-core (~> 3.7.0)
|
13
|
+
rspec-expectations (~> 3.7.0)
|
14
|
+
rspec-mocks (~> 3.7.0)
|
15
|
+
rspec-core (3.7.1)
|
16
|
+
rspec-support (~> 3.7.0)
|
17
|
+
rspec-expectations (3.7.0)
|
18
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
19
|
+
rspec-support (~> 3.7.0)
|
20
|
+
rspec-mocks (3.7.0)
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
+
rspec-support (~> 3.7.0)
|
23
|
+
rspec-support (3.7.1)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
boring!
|
30
|
+
bundler (~> 1.16)
|
31
|
+
rake (~> 10.0)
|
32
|
+
rspec (~> 3.0)
|
33
|
+
|
34
|
+
BUNDLED WITH
|
35
|
+
1.16.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Wyatt Kirby
|
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,39 @@
|
|
1
|
+
# Boring
|
2
|
+
|
3
|
+
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/boring`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'boring'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install boring
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
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.
|
30
|
+
|
31
|
+
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).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/wkirby/boring.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "boring"
|
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
data/boring.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'boring/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'boring_presenters'
|
7
|
+
spec.version = Boring::VERSION
|
8
|
+
spec.authors = ['Wyatt Kirby', "Noah Callaway"]
|
9
|
+
spec.email = ['wyatt@apsis.io', "noah@apsis.io"]
|
10
|
+
|
11
|
+
spec.summary = 'A boring presentation layer.'
|
12
|
+
spec.homepage = 'http://www.apsis.io'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
16
|
+
f.match(%r{^(test|spec|features)/})
|
17
|
+
end
|
18
|
+
spec.bindir = 'exe'
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
spec.required_ruby_version = '~> 2.1'
|
22
|
+
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
24
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
25
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
26
|
+
end
|
File without changes
|
@@ -0,0 +1,150 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Boring
|
4
|
+
class Presenter #:nodoc:
|
5
|
+
extend Forwardable
|
6
|
+
|
7
|
+
class << self
|
8
|
+
attr_accessor :__arguments
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
# Takes a list of arguments and types that will
|
13
|
+
# be passed to the +bind+ method, and defines
|
14
|
+
# the +initialize+ and +bind+ methods.
|
15
|
+
#
|
16
|
+
# arguments hash: Hash # => bind presenter to a Hash
|
17
|
+
def arguments(args)
|
18
|
+
@__arguments = args.nil? ? {} : args
|
19
|
+
|
20
|
+
class_eval do
|
21
|
+
unless method_defined?(:initialize)
|
22
|
+
define_method(:initialize) do |**bindings|
|
23
|
+
# dies if nil or empty
|
24
|
+
self.class.__arguments.each do |arg_name, arg_class|
|
25
|
+
arg_value = bindings[arg_name]
|
26
|
+
|
27
|
+
# Ensure all of our bindings are the appropriate type
|
28
|
+
if bindings.key?(arg_name) && !arg_value.is_a?(arg_class)
|
29
|
+
raise ArgumentError, "Argument '#{arg_name}' is of type #{arg_value.class}, expecting #{arg_class}."
|
30
|
+
end
|
31
|
+
|
32
|
+
instance_variable_set("@#{arg_name}", arg_value)
|
33
|
+
end
|
34
|
+
|
35
|
+
# Ensure we don't have any unexpected arguments
|
36
|
+
extra_bindings = (bindings.keys - args.keys)
|
37
|
+
|
38
|
+
unless extra_bindings.empty?
|
39
|
+
raise ArgumentError, "Unexpected argument: #{extra_bindings.join(', ')}."
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
unless method_defined?(:bind)
|
45
|
+
define_method(:bind) do |**bindings|
|
46
|
+
self.class.__arguments.each.each do |arg_name, arg_class|
|
47
|
+
arg_value = bindings[arg_name]
|
48
|
+
|
49
|
+
unless arg_value.is_a?(arg_class)
|
50
|
+
raise ArgumentError, "Argument '#{arg_name}' is of type #{arg_value.class}, expecting #{arg_class}."
|
51
|
+
end
|
52
|
+
|
53
|
+
instance_variable_set("@#{arg_name}", arg_value)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# TODO: Move to rails extension helper
|
59
|
+
# unless method_defined?(:render)
|
60
|
+
# define_method(:render) do |**render_args|
|
61
|
+
# view_context.render(**render_args)
|
62
|
+
# end
|
63
|
+
# end
|
64
|
+
|
65
|
+
# unless method_defined?(:view_context)
|
66
|
+
# define_method(:view_context) do
|
67
|
+
# @__view_context ||= ActionView::Base.new(
|
68
|
+
# ActionController::Base.view_paths,
|
69
|
+
# {}
|
70
|
+
# )
|
71
|
+
# end
|
72
|
+
# end
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
attr_reader(*args.keys)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
# Process all methods on the presenter class
|
81
|
+
# and add a processing step where we will
|
82
|
+
# check whether or not the presenter bindings
|
83
|
+
# are set up properly.
|
84
|
+
#
|
85
|
+
# The wrapped method is aliased to the original
|
86
|
+
# method name, while a new method is defined
|
87
|
+
# as +{method_name}_without_before_each_method+
|
88
|
+
# that will call the original, unwrapped method.
|
89
|
+
def method_added(method_name)
|
90
|
+
return if self == Boring::Presenter
|
91
|
+
return if @__last_methods_added && @__last_methods_added.include?(method_name)
|
92
|
+
|
93
|
+
skipped_methods = %i[initialize render bind]
|
94
|
+
return if skipped_methods.include?(method_name)
|
95
|
+
|
96
|
+
skipped_methods = @__arguments.keys
|
97
|
+
return if skipped_methods.include?(method_name)
|
98
|
+
|
99
|
+
with = :"#{method_name}_with_before_each_method"
|
100
|
+
without = :"#{method_name}_without_before_each_method"
|
101
|
+
|
102
|
+
@__last_methods_added = [method_name, with, without]
|
103
|
+
define_method with do |*args, &block|
|
104
|
+
before_each_method method_name
|
105
|
+
send without, *args, &block
|
106
|
+
end
|
107
|
+
|
108
|
+
alias_method without, method_name
|
109
|
+
alias_method method_name, with
|
110
|
+
|
111
|
+
@__last_methods_added = nil
|
112
|
+
end
|
113
|
+
|
114
|
+
# Shorthand for adding delegation between two
|
115
|
+
# objects, wrapping the +def_delegators+
|
116
|
+
# method from +Forwardable+
|
117
|
+
#
|
118
|
+
# delegate :foo, to: :bar # => delegates +foo+ to +bar+
|
119
|
+
def delegate(*methods)
|
120
|
+
options = methods.pop
|
121
|
+
|
122
|
+
unless options.is_a?(Hash) && to = options[:to]
|
123
|
+
raise ArgumentError, 'Delegation needs a target. Supply an options hash with a :to key as the last argument.'
|
124
|
+
end
|
125
|
+
|
126
|
+
def_delegators(to, *methods)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
private
|
131
|
+
|
132
|
+
# This method is called before each bound method
|
133
|
+
# and ensures that the proper arguments have
|
134
|
+
# been bound to the presenter before we proceed.
|
135
|
+
def before_each_method(*)
|
136
|
+
# Ensure everything is properly bound before invoking this method
|
137
|
+
self.class.__arguments.each do |arg_name, arg_class|
|
138
|
+
arg_value = send(arg_name.to_sym)
|
139
|
+
|
140
|
+
if arg_name.nil?
|
141
|
+
raise ArgumentError, "Argument '#{arg_name}' is not bound."
|
142
|
+
end
|
143
|
+
|
144
|
+
unless arg_value.is_a?(arg_class)
|
145
|
+
raise ArgumentError, "Argument '#{arg_name}' is of type #{arg_value.class}, expecting #{arg_class}."
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
data/lib/boring.rb
ADDED
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: boring_presenters
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Wyatt Kirby
|
8
|
+
- Noah Callaway
|
9
|
+
autorequire:
|
10
|
+
bindir: exe
|
11
|
+
cert_chain: []
|
12
|
+
date: 2018-02-10 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.16'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.16'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '10.0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '10.0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rspec
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '3.0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '3.0'
|
56
|
+
description:
|
57
|
+
email:
|
58
|
+
- wyatt@apsis.io
|
59
|
+
- noah@apsis.io
|
60
|
+
executables: []
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- ".gitignore"
|
65
|
+
- ".rspec"
|
66
|
+
- ".travis.yml"
|
67
|
+
- Gemfile
|
68
|
+
- Gemfile.lock
|
69
|
+
- LICENSE.txt
|
70
|
+
- README.md
|
71
|
+
- Rakefile
|
72
|
+
- bin/console
|
73
|
+
- bin/setup
|
74
|
+
- boring.gemspec
|
75
|
+
- lib/boring.rb
|
76
|
+
- lib/boring/exceptions.rb
|
77
|
+
- lib/boring/presenter.rb
|
78
|
+
- lib/boring/version.rb
|
79
|
+
homepage: http://www.apsis.io
|
80
|
+
licenses:
|
81
|
+
- MIT
|
82
|
+
metadata: {}
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - "~>"
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '2.1'
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
requirements: []
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 2.6.13
|
100
|
+
signing_key:
|
101
|
+
specification_version: 4
|
102
|
+
summary: A boring presentation layer.
|
103
|
+
test_files: []
|