pretty_feed 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/lib/pretty_feed/compat.rb +17 -15
- data/lib/pretty_feed/pf_tf.rb +2 -2
- data/lib/pretty_feed/version.rb +1 -1
- data/spec/pretty_feed/pf_tf_spec.rb +55 -52
- data/spec/spec_helper.rb +7 -3
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 17c30588dd58871f5a984e967e4e808d52da0acabebdf584a26c2dae1b347949
|
4
|
+
data.tar.gz: a1f8d1b0a9a535c479db007b81df251a480f231a7b8748cf565a57b31f36cbb0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 15ed9ff39b39eec2cd158cdd4812e771b125ed07cb2c380b92063db59bc37f9600c7e85598b85a54c22478afa843574744020997647242fac4685753013eea7c
|
7
|
+
data.tar.gz: d399c722f2e9c964e7214e3cb519be946ca14625e23c6098bb73e2d51f56e27ac8cc25317286a0f3d7cdbdd7c53e84b1d4fcd2bc317f939015d4a6b7f5f4bf2d
|
data/README.md
CHANGED
@@ -22,9 +22,9 @@ If bundler is not being used to manage dependencies, install the gem by executin
|
|
22
22
|
namespace :scrub do
|
23
23
|
task :blurb => :environment do |_t, _args|
|
24
24
|
include PrettyFeed::PfTf.new(truthy: 'green', falsey: 'blue')
|
25
|
-
|
25
|
+
pftf("this will be green", true)
|
26
26
|
# => "this will be green" # in the console
|
27
|
-
|
27
|
+
pftf("this will be blue", false)
|
28
28
|
# => "this will be blue" # in the console
|
29
29
|
end
|
30
30
|
end
|
@@ -36,7 +36,7 @@ Instead of passing truthy or falsey values, you can pass a proc that will be eva
|
|
36
36
|
namespace :scrub do
|
37
37
|
task :blurb => :environment do |_t, someth|
|
38
38
|
include PrettyFeed::PfTf.new(truthy: 'green', falsey: 'blue')
|
39
|
-
|
39
|
+
pftf("might be green or blue", someth, ->(a) { a })
|
40
40
|
# => the color will depend on what someth is and how the proc evaluates it.
|
41
41
|
end
|
42
42
|
end
|
data/lib/pretty_feed/compat.rb
CHANGED
@@ -3,24 +3,26 @@
|
|
3
3
|
module PrettyFeed
|
4
4
|
# Provide compatibility with Polluted and Unpolluted Strings
|
5
5
|
module Compat
|
6
|
-
module_function
|
7
|
-
|
8
6
|
define_method(:[]) do |str, color|
|
9
|
-
if defined?(ColorizedString)
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
end
|
7
|
+
return ColorizedString[str] if defined?(ColorizedString)
|
8
|
+
return str if str.respond_to?(color.to_sym)
|
9
|
+
|
10
|
+
dstr = str.dup
|
11
|
+
dstr.singleton_class.send(:include, color_stub(str, color))
|
12
|
+
dstr
|
13
|
+
end
|
14
|
+
module_function :[]
|
15
|
+
|
16
|
+
private
|
20
17
|
|
21
|
-
|
22
|
-
|
18
|
+
def color_stub(str, color)
|
19
|
+
Module.new do
|
20
|
+
define_method(color.to_sym) do
|
21
|
+
warn "Adding stub for missing '#{str}'.#{color}"
|
22
|
+
self
|
23
|
+
end
|
23
24
|
end
|
24
25
|
end
|
26
|
+
module_function :color_stub
|
25
27
|
end
|
26
28
|
end
|
data/lib/pretty_feed/pf_tf.rb
CHANGED
@@ -8,9 +8,9 @@ module PrettyFeed
|
|
8
8
|
# namespace :scrub do
|
9
9
|
# task :blurb => :environment do |_t, args|
|
10
10
|
# include PrettyFeed::PfTf.new(truthy: 'green', falsey: 'blue')
|
11
|
-
#
|
11
|
+
# pftf("this will be green", true)
|
12
12
|
# # => "this will be green" # but in green
|
13
|
-
#
|
13
|
+
# pftf("this will be blue", false)
|
14
14
|
# # => "this will be blue" # but in blue
|
15
15
|
# end
|
16
16
|
# end
|
data/lib/pretty_feed/version.rb
CHANGED
@@ -2,77 +2,80 @@
|
|
2
2
|
|
3
3
|
RSpec.describe PrettyFeed::PfTf do
|
4
4
|
subject(:pftfer) { ExamplePfff.new }
|
5
|
+
let(:caught) { COMPAT_LIB.nil? ? :stderr : :stdout }
|
6
|
+
let(:str) { "pear: " }
|
7
|
+
let(:truthy_value) { :cake }
|
8
|
+
let(:falsey_value) { false }
|
9
|
+
let(:color_open) { Regexp.escape("\e[") }
|
10
|
+
let(:color_close) { Regexp.escape("\e[0m\n") }
|
11
|
+
let(:falsey_out) { capture(caught) { pftfer.pftf(str, falsey_value) } }
|
12
|
+
let(:truthy_out) { capture(caught) { pftfer.pftf(str, truthy_value) } }
|
13
|
+
let(:falsey_out_proc) { capture(caught) { pftfer.pftf(str, falsey_value, ->(a) { a }) } }
|
14
|
+
let(:truthy_out_proc) { capture(caught) { pftfer.pftf(str, truthy_value, ->(a) { !a.nil? }) } }
|
15
|
+
let(:truthy_color) { :green }
|
16
|
+
let(:falsey_color) { :red }
|
17
|
+
|
5
18
|
shared_examples_for "ptft call" do
|
6
19
|
it "#pftf returns nil when truthy" do
|
7
|
-
expect(pftfer.pftf(
|
20
|
+
expect(pftfer.pftf(str, truthy_value)).to be_nil
|
21
|
+
end
|
22
|
+
it "#pftf returns nil when proc is truthy" do
|
23
|
+
expect(pftfer.pftf(str, truthy_value, ->(a) { !a.nil? })).to be_nil
|
8
24
|
end
|
9
25
|
it "#pftf returns nil when falsey" do
|
10
|
-
expect(pftfer.pftf(
|
26
|
+
expect(pftfer.pftf(str, falsey_value)).to be_nil
|
27
|
+
end
|
28
|
+
it "#pftf returns nil when proc is falsey" do
|
29
|
+
expect(pftfer.pftf(str, falsey_value, ->(a) { !a })).to be_nil
|
11
30
|
end
|
12
31
|
it "#pftf includes prefix when truthy" do
|
13
|
-
|
14
|
-
|
15
|
-
|
32
|
+
expect(truthy_out).to match("#{str}#{truthy_value}")
|
33
|
+
end
|
34
|
+
it "#pftf includes prefix when proc is truthy" do
|
35
|
+
expect(truthy_out_proc).to match("#{str}#{truthy_value}")
|
16
36
|
end
|
17
37
|
it "#pftf includes prefix when falsey" do
|
18
|
-
|
19
|
-
output = capture(:stdout) { pftfer.pftf(str, false) }
|
20
|
-
expect(output).to match(str)
|
38
|
+
expect(falsey_out).to match("#{str}#{falsey_value}")
|
21
39
|
end
|
22
|
-
|
23
|
-
|
24
|
-
it_behaves_like "ptft call"
|
25
|
-
it "#pftf has output when falsey" do
|
26
|
-
if COMPAT_LIB.nil?
|
27
|
-
output = capture(:stderr) { pftfer.pftf("hi: ", false) }
|
28
|
-
expect(output).to eq("String 'hi: false' doesn't respond to red\n")
|
29
|
-
elsif COMPAT_LIB == :cs
|
30
|
-
output = capture(:stdout) { pftfer.pftf("hi: ", false) }
|
31
|
-
expect(output).to eq("\e[0;31;49mhi: false\e[0m\n")
|
32
|
-
else
|
33
|
-
output = capture(:stdout) { pftfer.pftf("hi: ", false) }
|
34
|
-
expect(output).to eq("\e[1;31mhi: false\e[0m\n")
|
40
|
+
it "#pftf includes prefix when proc is falsey" do
|
41
|
+
expect(falsey_out_proc).to match("#{str}#{falsey_value}")
|
35
42
|
end
|
36
|
-
end
|
37
|
-
it "#pftf has output when truthy" do
|
38
|
-
if COMPAT_LIB.nil?
|
39
|
-
output = capture(:stderr) { pftfer.pftf("hi: ", true) }
|
40
|
-
expect(output).to eq("String 'hi: true' doesn't respond to green\n")
|
41
|
-
elsif COMPAT_LIB == :cs
|
42
|
-
output = capture(:stdout) { pftfer.pftf("hi: ", true) }
|
43
|
-
expect(output).to eq("\e[0;32;49mhi: true\e[0m\n")
|
44
|
-
else
|
45
|
-
output = capture(:stdout) { pftfer.pftf("hi: ", true) }
|
46
|
-
expect(output).to eq("\e[1;32mhi: true\e[0m\n")
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
context "when custom color" do
|
51
|
-
subject(:pftfer) { ExamplePfffColors.new }
|
52
|
-
it_behaves_like "ptft call"
|
53
43
|
it "#pftf has output when falsey" do
|
54
44
|
if COMPAT_LIB.nil?
|
55
|
-
|
56
|
-
expect(output).to eq("String 'hi: false' doesn't respond to yellow\n")
|
57
|
-
elsif COMPAT_LIB == :cs
|
58
|
-
output = capture(:stdout) { pftfer.pftf("hi: ", false) }
|
59
|
-
expect(output).to eq("\e[0;33;49mhi: false\e[0m\n")
|
45
|
+
expect(falsey_out).to eq("Adding stub for missing '#{str}#{falsey_value}'.#{falsey_color}\n")
|
60
46
|
else
|
61
|
-
|
62
|
-
|
47
|
+
expect(falsey_out).to match(/#{color_open}.*\d{2}m#{Regexp.escape(str.to_s)}#{Regexp.escape(falsey_value.to_s)}#{color_close}/)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
it "#pftf has output when falsey proc" do
|
51
|
+
if COMPAT_LIB.nil?
|
52
|
+
expect(falsey_out_proc).to eq("Adding stub for missing '#{str}#{falsey_value}'.#{falsey_color}\n")
|
53
|
+
else
|
54
|
+
expect(falsey_out_proc).to match(/#{color_open}.*\d{2}m#{Regexp.escape(str.to_s)}#{Regexp.escape(falsey_value.to_s)}#{color_close}/)
|
63
55
|
end
|
64
56
|
end
|
65
57
|
it "#pftf has output when truthy" do
|
66
58
|
if COMPAT_LIB.nil?
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
59
|
+
expect(truthy_out).to eq("Adding stub for missing '#{str}#{truthy_value}'.#{truthy_color}\n")
|
60
|
+
else
|
61
|
+
expect(truthy_out).to match(/#{color_open}.*\d{2}m#{Regexp.escape(str.to_s)}#{Regexp.escape(truthy_value.to_s)}#{color_close}/)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
it "#pftf has output when truthy proc" do
|
65
|
+
if COMPAT_LIB.nil?
|
66
|
+
expect(truthy_out_proc).to eq("Adding stub for missing '#{str}#{truthy_value}'.#{truthy_color}\n")
|
72
67
|
else
|
73
|
-
|
74
|
-
expect(output).to eq("\e[1;35mhi: true\e[0m\n")
|
68
|
+
expect(truthy_out_proc).to match(/#{color_open}.*\d{2}m#{Regexp.escape(str.to_s)}#{Regexp.escape(truthy_value.to_s)}#{color_close}/)
|
75
69
|
end
|
76
70
|
end
|
77
71
|
end
|
72
|
+
|
73
|
+
it_behaves_like "ptft call"
|
74
|
+
|
75
|
+
context "when custom color" do
|
76
|
+
subject(:pftfer) { ExamplePfffColors.new }
|
77
|
+
let(:truthy_color) { :cyan }
|
78
|
+
let(:falsey_color) { :yellow }
|
79
|
+
it_behaves_like "ptft call"
|
80
|
+
end
|
78
81
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -20,12 +20,16 @@ end
|
|
20
20
|
|
21
21
|
COMPAT_LIB = compat_lib
|
22
22
|
DEBUG = ENV["DEBUG"] == "true"
|
23
|
-
RUN_COVERAGE = ENV["CI_CODECOV"] || ENV["CI"].nil?
|
24
23
|
|
25
24
|
ruby_version = Gem::Version.new(RUBY_VERSION)
|
26
25
|
minimum_version = ->(version, engine = "ruby") { ruby_version >= Gem::Version.new(version) && RUBY_ENGINE == engine }
|
27
|
-
|
26
|
+
actual_version = lambda do |major, minor|
|
27
|
+
actual = Gem::Version.new(ruby_version)
|
28
|
+
major == actual.segments[0] && minor == actual.segments[1] && RUBY_ENGINE == "ruby"
|
29
|
+
end
|
28
30
|
debugging = minimum_version.call("2.7") && DEBUG
|
31
|
+
RUN_COVERAGE = minimum_version.call("2.6") && (ENV["COVER_ALL"] || ENV["CI_CODECOV"] || ENV["CI"].nil?)
|
32
|
+
ALL_FORMATTERS = actual_version.call(2, 7) && (ENV["COVER_ALL"] || ENV["CI_CODECOV"] || ENV["CI"])
|
29
33
|
|
30
34
|
if DEBUG
|
31
35
|
if debugging
|
@@ -35,7 +39,7 @@ if DEBUG
|
|
35
39
|
end
|
36
40
|
end
|
37
41
|
|
38
|
-
require "simplecov" if
|
42
|
+
require "simplecov" if RUN_COVERAGE
|
39
43
|
|
40
44
|
# This gem
|
41
45
|
require "pretty_feed"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pretty_feed
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Boling
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-03-
|
11
|
+
date: 2022-03-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -126,10 +126,10 @@ licenses:
|
|
126
126
|
- MIT
|
127
127
|
metadata:
|
128
128
|
homepage_uri: https://github.com/pboling/pretty_feed
|
129
|
-
source_code_uri: https://github.com/pboling/pretty_feed/tree/v0.1.
|
130
|
-
changelog_uri: https://github.com/pboling/pretty_feed/blob/v0.1.
|
129
|
+
source_code_uri: https://github.com/pboling/pretty_feed/tree/v0.1.1
|
130
|
+
changelog_uri: https://github.com/pboling/pretty_feed/blob/v0.1.1/CHANGELOG.md
|
131
131
|
bug_tracker_uri: https://github.com/pboling/pretty_feed/issues
|
132
|
-
documentation_uri: https://www.rubydoc.info/gems/pretty_feed/0.1.
|
132
|
+
documentation_uri: https://www.rubydoc.info/gems/pretty_feed/0.1.1
|
133
133
|
wiki_uri: https://github.com/pboling/pretty_feed/wiki
|
134
134
|
rubygems_mfa_required: 'true'
|
135
135
|
post_install_message:
|