o_lo 0.0.1 → 0.0.3

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: 61959a8a7ce1427a8b1d3d668892bd7189d8f6df9fcf35c2b653d77746a6404f
4
- data.tar.gz: f3b5f595a68c185469e22f8899d3fa7c30d49934ec091a6eb8944f6626c777ae
3
+ metadata.gz: 2a5a812346059789bf9154aba27398c921afc583a04ae19083c21f885f319617
4
+ data.tar.gz: eb11db020a360e1d278052a13cd5742e06f6e00476d568811c2002f76a6a9b45
5
5
  SHA512:
6
- metadata.gz: 8e88778f298fea3c193b8a33d4c7be6f6ce550eb70b5d1598f5ba0b896570ddaba665fd9d531506298bef441813e4169bca42af62f7eeb2bb4891a66e019a7ad
7
- data.tar.gz: be1f4066b6fdd4fe1e40628fb96bff865196ffbe32a3d66bef3cba7879ea2d72d7a413814a0bf6021235cc8b275257ccc3916edcefd5c90fb9aa2269d18ea7b8
6
+ metadata.gz: 48f7cc499b9da69cfb3c9f51a4feba51acc6bd7a62f2ca414601abb77fdec2f6079bc628f6e78b5d509afa74728c072a7544f9619dc8ca999cdcf0d2f23dfcc8
7
+ data.tar.gz: 6978071862f807c4b2e7727a48724b5e1aae966ab1ad1a16a8f9a10d1aced551ca722b79b89298cffdc0e814069a9d8181e6df2d66e4150377ee9bb5aec2c9d5
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ log/**
2
+ pkg/**
3
+ .DS_Store
4
+ lib/.DS_Store
5
+ .*.swp
6
+ coverage.data
7
+ tags
8
+ .bundle
9
+ *.gem
10
+ Gemfile*.lock
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source 'https://rubygems.org'
2
+
3
+ git_source(:github) do |repo_name|
4
+ repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?('/')
5
+ "https://github.com/#{repo_name}.git"
6
+ end
7
+
8
+ gemspec
9
+
10
+ gem 'rails'
11
+
12
+ gem 'rspec'
13
+ gem 'guard'
14
+ gem 'guard-rspec'
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Ryan S Stuhl
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,76 @@
1
+ # Olo
2
+
3
+ Olo is short for Obvious Logger. It allows developers to output a decorated version of an Object (String, Integer, Class, etc) in the rails console.
4
+
5
+ Best practice is to use Olo in development mode or custom mode (staging, profile, etc.). Using in production could have nasty consequences and just isn't worth the headaches.
6
+
7
+ ## Install
8
+
9
+ You can add Olo as a gem:
10
+
11
+ ```
12
+ gem install o_lo
13
+ ```
14
+
15
+ or add it to a Gemfile (Bundler):
16
+
17
+ ```ruby
18
+ gem 'o_lo', group: 'development'
19
+ ```
20
+
21
+ ## Usage
22
+
23
+ Olo is set up to work from any controller, model, or view.
24
+
25
+ In a controller or model:
26
+
27
+ ```ruby
28
+ Olo.log("something to log", "%", 100)
29
+ ```
30
+
31
+ In a view
32
+
33
+ ```
34
+ #ERB
35
+ <% meaningful_variable = User.email %>
36
+ <% Olo.log(meaningful_variable, ":", 42) %>
37
+
38
+ #HAML
39
+ - meaningful_variable = User.email
40
+ - Olo.log(meaningful_variable, ":", 42)
41
+ ```
42
+
43
+ The arguments for Olo.log are:
44
+
45
+ - thing: The string, variable, or value of a thing you want to output to the stdout logs _(\* required)_
46
+ - decorator: Any string value that will be repeated to provide a visual way to find the output log _(optional, default is "\*")_
47
+ - decorator: length: How many times the decorator will be repeated. The max is 200. _(optional, default is 100)_
48
+
49
+ ## Output
50
+
51
+ ```ruby
52
+ thing = "Thanks for all the fish"
53
+ decorator = "ß"
54
+ decorator_length = 42
55
+ Olo.log(thing, decorator, decorator_length)
56
+ ```
57
+
58
+ ```
59
+ # output
60
+
61
+
62
+
63
+ ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß
64
+ ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß
65
+ ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß
66
+
67
+ Thanks for all the fish
68
+
69
+ ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß
70
+ ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß
71
+ ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß
72
+
73
+
74
+
75
+ #end of output
76
+ ```
data/bin/o_lo ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'o_lo'
4
+ puts Olo.log("Greetings")
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'o_lo'
@@ -0,0 +1,3 @@
1
+ module Olo
2
+ VERSION = '0.0.3'
3
+ end
data/lib/o_lo.rb ADDED
@@ -0,0 +1,38 @@
1
+ require 'action_controller'
2
+ require 'active_record'
3
+ require 'action_view'
4
+
5
+ module Olo
6
+ ActionController::Base.send(:include, Olo)
7
+ ActiveRecord::Base.send(:include, Olo)
8
+ ActionView::Base.send(:include, Olo)
9
+
10
+ def self.log(thing, decorator="*", decorator_length=100)
11
+ decorator_length = validate_decorator_length(decorator_length)
12
+ decorator = validate_decorator(decorator)
13
+ return if thing.nil?
14
+ 3.times { puts "" }
15
+ 3.times { puts "#{decorator}" * decorator_length }
16
+ puts ""
17
+ puts thing
18
+ puts ""
19
+ 3.times { puts "#{decorator}" * decorator_length }
20
+ 3.times { puts "" }
21
+ end
22
+
23
+ private
24
+
25
+ def self.validate_decorator_length(length)
26
+ length = 0 if length.nil?
27
+ length = 100 if length < 1
28
+ length = 100 if !length.is_a?(Integer)
29
+ length = 200 if length > 200
30
+ length
31
+ end
32
+
33
+ def self.validate_decorator(decorator)
34
+ decorator = decorator.to_s if decorator.is_a?(Integer)
35
+ decorator = "*" if !decorator.is_a?(String)
36
+ decorator
37
+ end
38
+ end
data/o_lo.gemspec ADDED
@@ -0,0 +1,20 @@
1
+ lib = File.expand_path('lib', __dir__)
2
+ $LOAD_PATH.unshift lib unless $LOAD_PATH.include?(lib)
3
+
4
+ require 'o_lo/version'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = 'o_lo'
8
+ s.version = Olo::VERSION
9
+ s.executables << 'o_lo'
10
+ s.platform = Gem::Platform::RUBY
11
+ s.summary = 'Obvious Logger for use in development.'
12
+ s.description = 'Displays output in logs with decorators, making it easy to find in a log stream.'
13
+ s.authors = ["Ryan Stuhl"]
14
+ s.email = "designstuhltech@gmail.com"
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.require_paths = ['lib']
18
+ s.homepage = 'https://rubygems.org/gems/o_lo'
19
+ s.license = 'MIT'
20
+ end
data/spec/o_lo_spec.rb ADDED
@@ -0,0 +1,85 @@
1
+ require 'spec_helper'
2
+
3
+ describe ::Olo do
4
+ subject { Olo.log(thing, decorator, decorator_length) }
5
+
6
+ describe "#log" do
7
+ context "happy path" do
8
+ context "thing is a string" do
9
+ let(:thing) { "Testing the output of a string in o_lo." }
10
+ let(:decorator) { "#" }
11
+ let(:decorator_length) { 99 }
12
+
13
+ it "calls log and outputs a string including the decorator" do
14
+ expect{subject}.to output(a_string_including(decorator * decorator_length)).to_stdout
15
+ end
16
+
17
+ it "calls log and outputs a string including the thing" do
18
+ expect{subject}.to output(a_string_including(thing)).to_stdout
19
+ end
20
+ end
21
+
22
+ context "thing is an object" do
23
+ let(:thing) { Object.new }
24
+ let(:decorator) { "^" }
25
+ let(:decorator_length) { 42 }
26
+
27
+ it "calls log and outputs a string including the decorator" do
28
+ expect{subject}.to output(a_string_including(decorator * decorator_length)).to_stdout
29
+ end
30
+
31
+ it "calls log and outputs an object" do
32
+ expect{subject}.to output(a_string_including(thing.inspect)).to_stdout
33
+ end
34
+ end
35
+
36
+ context "thing is defined but decorator and decorator_length are not" do
37
+ let(:thing) { "Thanks for all the fish!" }
38
+ let(:decorator) { nil }
39
+ let(:decorator_length) { nil}
40
+ end
41
+ end
42
+
43
+ context "sad path" do
44
+ context "thing is blank" do
45
+ let(:thing) { nil }
46
+ let(:decorator) { nil }
47
+ let(:decorator_length) { nil }
48
+
49
+ it "does not output anything" do
50
+ expect{subject}.not_to output(a_string_including("*" * 100)).to_stdout
51
+ end
52
+ end
53
+
54
+ context "decorator is an object" do
55
+ let(:thing) { "Some people like to watch the world burn" }
56
+ let(:decorator) { Object.new }
57
+ let(:decorator_length) { 42 }
58
+
59
+ it "omits the decorator if it is an object" do
60
+ expect{subject}.to output(a_string_including("*" * decorator_length)).to_stdout
61
+ end
62
+ end
63
+
64
+ context "decorator is an integer" do
65
+ let(:thing) { Object.new }
66
+ let(:decorator) { 7 }
67
+ let(:decorator_length) { nil }
68
+
69
+ it "sets the decorator to a stringified version of itself" do
70
+ expect{subject}.to output(a_string_including("7" * 100)).to_stdout
71
+ end
72
+ end
73
+
74
+ context "decorator_length is greater than 200" do
75
+ let(:thing) { Object.new }
76
+ let(:decorator) { "!" }
77
+ let(:decorator_length) { 1000 }
78
+
79
+ it "truncates the decorator length if it is over 200" do
80
+ expect{subject}.not_to output(a_string_including(decorator * decorator_length)).to_stdout
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,4 @@
1
+ require 'rspec'
2
+
3
+ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '/../lib'))
4
+ require 'o_lo'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: o_lo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Stuhl
@@ -13,10 +13,23 @@ dependencies: []
13
13
  description: Displays output in logs with decorators, making it easy to find in a
14
14
  log stream.
15
15
  email: designstuhltech@gmail.com
16
- executables: []
16
+ executables:
17
+ - o_lo
17
18
  extensions: []
18
19
  extra_rdoc_files: []
19
- files: []
20
+ files:
21
+ - ".gitignore"
22
+ - ".rspec"
23
+ - Gemfile
24
+ - LICENSE
25
+ - README.md
26
+ - bin/o_lo
27
+ - init.rb
28
+ - lib/o_lo.rb
29
+ - lib/o_lo/version.rb
30
+ - o_lo.gemspec
31
+ - spec/o_lo_spec.rb
32
+ - spec/spec_helper.rb
20
33
  homepage: https://rubygems.org/gems/o_lo
21
34
  licenses:
22
35
  - MIT
@@ -40,4 +53,6 @@ rubygems_version: 3.1.4
40
53
  signing_key:
41
54
  specification_version: 4
42
55
  summary: Obvious Logger for use in development.
43
- test_files: []
56
+ test_files:
57
+ - spec/o_lo_spec.rb
58
+ - spec/spec_helper.rb