pretty_feed 0.1.0 → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9092c93db2f35d0d54b1194e6044e7183b37af1faca2a10eab4b2b5ba81c38e8
4
- data.tar.gz: 74d467066d0c10d78ad82f10dc1a74d7e90a4da6b716541aed106d60304d9d48
3
+ metadata.gz: 17c30588dd58871f5a984e967e4e808d52da0acabebdf584a26c2dae1b347949
4
+ data.tar.gz: a1f8d1b0a9a535c479db007b81df251a480f231a7b8748cf565a57b31f36cbb0
5
5
  SHA512:
6
- metadata.gz: 4a828968a0a4525a47c631c73fa10c18be3a4f912f47089d0b66e4aa136909e74bc80cf777bffa3ed5de0330a37ba2481e9856218eef5764dae866f0546c30b1
7
- data.tar.gz: 223a4bcfc83f2ee7b39fd31b8504770bea3fc34db2f908121884ec805645831a05ab6a5b4222b58827ced389f36286ea6438568e776499ed70f05b3afc4685f6
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
- pf("this will be green", true)
25
+ pftf("this will be green", true)
26
26
  # => "this will be green" # in the console
27
- pf("this will be blue", false)
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
- pf("might be green or blue", someth, ->(a) { a })
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
@@ -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
- ColorizedString[str]
11
- elsif str.respond_to?(color.to_sym)
12
- str
13
- else
14
- mod = Module.new do
15
- define_method(color.to_sym) do
16
- warn "String '#{self}' doesn't respond to #{color}"
17
- self
18
- end
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
- str.singleton_class.send(:include, mod)
22
- str
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
@@ -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
- # pf("this will be green", true)
11
+ # pftf("this will be green", true)
12
12
  # # => "this will be green" # but in green
13
- # pf("this will be blue", false)
13
+ # pftf("this will be blue", false)
14
14
  # # => "this will be blue" # but in blue
15
15
  # end
16
16
  # end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PrettyFeed
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
@@ -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("hi: ", true)).to be_nil
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("hi: ", false)).to be_nil
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
- str = "hi: "
14
- output = capture(:stdout) { pftfer.pftf(str, true) }
15
- expect(output).to match(str)
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
- str = "hi: "
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
- end
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
- output = capture(:stderr) { pftfer.pftf("hi: ", false) }
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
- output = capture(:stdout) { pftfer.pftf("hi: ", false) }
62
- expect(output).to eq("\e[1;33mhi: false\e[0m\n")
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
- output = capture(:stderr) { pftfer.pftf("hi: ", true) }
68
- expect(output).to eq("String 'hi: true' doesn't respond to cyan\n")
69
- elsif COMPAT_LIB == :cs
70
- output = capture(:stdout) { pftfer.pftf("hi: ", true) }
71
- expect(output).to eq("\e[0;36;49mhi: true\e[0m\n")
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
- output = capture(:stdout) { pftfer.pftf("hi: ", true) }
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
- coverage = minimum_version.call("2.7") && RUN_COVERAGE
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 coverage
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.0
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-21 00:00:00.000000000 Z
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.0
130
- changelog_uri: https://github.com/pboling/pretty_feed/blob/v0.1.0/CHANGELOG.md
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.0
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: