cputs 0.1.1 → 0.1.2

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
  SHA1:
3
- metadata.gz: e1d3d28e41a68ab5b79a4fb79956e44902089640
4
- data.tar.gz: 79f53672bdaa44c29c4335f20f1b2a956d559dd1
3
+ metadata.gz: 0c3a5103e5c704a4aa1cf9312b84b96fd84bcf0c
4
+ data.tar.gz: d270b38afd332642521a777a125250a82afa3aec
5
5
  SHA512:
6
- metadata.gz: 0771ec3cbe339855f85f4940e56a49182080534a8b50120637a3faf86b79b1459583179e927824f9066276bba283956958511a38bb817a54660616addaaf537a
7
- data.tar.gz: 50d78a19a1b1ec73273a33573d27d52361fdfce52a319220801efe78dc0a4e4921ad7996b659b2d1feb12d89bb58ccf4d4fbd1d4520d5bd58362bc91c4ca5023
6
+ metadata.gz: 4154a534b0782db49ad34127afb73fb5fb1572db9f1cb2bf017ce8de0e9d71b4bab9b7ff01d1a738994188d0e3edaa7e299889c504c7da04a6c8bf7f4734999e
7
+ data.tar.gz: 57dfb4584a5132e31fba81425ff71df00125fa6577a37d27a40f763fe72574e8239c5843e1fcc2ba91177dbf61178a8408f230d68db7b2a83e369a4b82d001ce
data/.gitignore CHANGED
@@ -8,3 +8,4 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  .idea/
11
+ *.gem
data/Gemfile CHANGED
@@ -2,4 +2,4 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in cputs.gemspec
4
4
  gemspec
5
- gem 'rspec'
5
+ gem 'rspec'
data/README.md CHANGED
@@ -28,6 +28,13 @@ Or using a preffix and/or suffix to make the output more noticeable:
28
28
  <----------------------------
29
29
  ```
30
30
 
31
+ You could also add a Timestamp to every output
32
+ ```
33
+ ---------------------------->
34
+ 2016-01-03T18:28:32 /Users/JGutierrezC/AwesomeProjects/the_best/app/controllers/randoms_controller at line 2: Project4 - The name is still to decide. user jgutierrezc
35
+ <----------------------------
36
+ ```
37
+
31
38
  This way, you'll **NEVER** lose your output messages and hopefully they won't make it to production.
32
39
  ###Sometimes even the Gems are printing to your console. Find out which gem is doing that by using `CPuts.override_puts` :)
33
40
 
@@ -66,9 +73,16 @@ CPuts.set_preffix_and_suffix('-----------------')
66
73
  # to set different preffix and suffix in a single method for every output:
67
74
  CPuts.set_preffix_and_suffix('----------->', '<-----------')
68
75
 
76
+ # to set default timestamp to be shown along with the preffix:
77
+ CPuts.set_timestamp(true)
78
+
79
+ # to set a custom timestamp to be shown along with the preffix:
80
+ CPuts.set_timestamp('%H:%M:%S')
69
81
 
70
82
  ```
71
83
 
84
+ **Note:** Please refer to http://apidock.com/ruby/DateTime/strftime for time formatting
85
+
72
86
  And use cputs command to output your message:
73
87
 
74
88
  ```
@@ -93,9 +107,23 @@ The output will be as follows (previously defined preffix and suffix):
93
107
  ----------------------------> /Users/JGutierrezC/AwesomeProjects/the_best/app/controllers/randoms_controller at line 2: Project4 - The name is still to decide. user jgutierrezc <----------------------------
94
108
  ```
95
109
 
110
+ ### Defaults
111
+
112
+ By default preffix is
113
+ ```
114
+ ----------------->
115
+ ```
116
+
117
+ Timestamp format (if set) is
118
+ ```
119
+ %Y-%m-%dT%H:%M:%S (2016-01-03T18:28:32)
120
+ ```
121
+
122
+ Suffix is empty
123
+
96
124
  ### When using rails
97
125
 
98
- Add `puts` to your Gemfile and then add a cputs initializer:
126
+ Add `cputs` to your Gemfile and then add a cputs.rb initializer:
99
127
 
100
128
  ```
101
129
  # config/initializers/cputs.rb
@@ -17,7 +17,7 @@ module CPuts
17
17
  # Override the usual *puts* method to always use
18
18
  # cputs instead.
19
19
 
20
- def self.override_puts
20
+ def CPuts.override_puts
21
21
  require_relative 'cputs/override.rb'
22
22
  end
23
23
 
@@ -42,6 +42,16 @@ module CPuts
42
42
  CPuts::Functions.preffix_and_suffix *args
43
43
  end
44
44
 
45
+ ##
46
+ # Sets timestamp to be shown in the output. It can be:
47
+ # False to disable it
48
+ # True to enable it
49
+ # String with format, which also enables it
50
+
51
+ def CPuts.set_timestamp(format=nil)
52
+ CPuts::Functions.timestamp(format)
53
+ end
54
+
45
55
  alias :default_puts :puts
46
56
 
47
57
  end
@@ -1,31 +1,80 @@
1
1
  module CPuts
2
2
  module Functions
3
- attr :preffix, :suffix
3
+ class Decorators
4
+
5
+ attr_writer :preffix, :suffix
6
+
7
+ def preffix
8
+ @preffix ||= Decorators.default_preffix
9
+ "#{"#{formatted_time} " if formatted_time}#{@preffix}"
10
+ end
11
+
12
+ def suffix
13
+ @suffix ||= Decorators.default_suffix
14
+ end
15
+
16
+ def self.default_preffix
17
+ "----------------->"
18
+ end
19
+
20
+ def self.default_suffix
21
+ ''
22
+ end
23
+
24
+ def self.default_time_format
25
+ '%Y-%m-%dT%H:%M:%S'
26
+ end
27
+
28
+ def add_time_to_preffix(format=nil)
29
+ begin
30
+ @format = format
31
+ return unless @format
32
+ Time.now.strftime(@format)
33
+ raise Exception.new('') if @format == ''
34
+ rescue Exception => ex
35
+ @format = Decorators.default_time_format
36
+ print "Warning: Format #{format} is wrong. Please refer to http://apidock.com/ruby/DateTime/strftime"
37
+ end
38
+ end
39
+
40
+ private
41
+ def formatted_time
42
+ Time.now.strftime(@format) if @format
43
+ end
44
+ end
4
45
 
5
46
  def self.cputs(message, caller)
6
47
  matcher = caller.first.match(/^(.*)\:(\d+)/)
7
48
  file, line = matcher.captures[0..1] unless matcher.nil?
8
- default_puts "#{@preffix}#{file} at line #{line}: #{message}#{@suffix}"
49
+ default_puts "#{decorator.preffix}#{file} at line #{line}: #{message}#{decorator.suffix}"
9
50
  end
10
51
 
11
52
  def self.preffix(preffix)
12
- @preffix = preffix
53
+ decorator.preffix = preffix
13
54
  end
14
55
 
15
56
  def self.suffix(suffix)
16
- @suffix = suffix
57
+ decorator.suffix = suffix
17
58
  end
18
59
 
19
60
  def self.preffix_and_suffix(*args)
20
61
  case args.length
21
62
  when 1
22
- @preffix = args[0]
23
- @suffix = args[0]
63
+ decorator.preffix = args[0]
64
+ decorator.suffix = args[0]
24
65
  when 2
25
- @preffix = args[0]
26
- @suffix = args[1]
66
+ decorator.preffix = args[0]
67
+ decorator.suffix = args[1]
27
68
  end
28
69
  end
29
70
 
71
+ def self.timestamp(format)
72
+ decorator.add_time_to_preffix(format)
73
+ end
74
+
75
+ def self.decorator
76
+ @decorator ||= Decorators.new
77
+ end
78
+
30
79
  end
31
80
  end
@@ -1,3 +1,3 @@
1
1
  module Cputs
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,69 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cputs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - JGutierrezC
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-08-16 00:00:00.000000000 Z
11
+ date: 2016-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.10'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.10'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '10.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '3.0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '3.0'
69
69
  description: Custom Puts is as it's name says, a customized puts command that will
@@ -76,8 +76,8 @@ executables: []
76
76
  extensions: []
77
77
  extra_rdoc_files: []
78
78
  files:
79
- - .gitignore
80
- - .travis.yml
79
+ - ".gitignore"
80
+ - ".travis.yml"
81
81
  - CODE_OF_CONDUCT.md
82
82
  - Gemfile
83
83
  - LICENSE.txt
@@ -101,17 +101,17 @@ require_paths:
101
101
  - lib
102
102
  required_ruby_version: !ruby/object:Gem::Requirement
103
103
  requirements:
104
- - - '>='
104
+ - - ">="
105
105
  - !ruby/object:Gem::Version
106
106
  version: '0'
107
107
  required_rubygems_version: !ruby/object:Gem::Requirement
108
108
  requirements:
109
- - - '>='
109
+ - - ">="
110
110
  - !ruby/object:Gem::Version
111
111
  version: '0'
112
112
  requirements: []
113
113
  rubyforge_project:
114
- rubygems_version: 2.4.6
114
+ rubygems_version: 2.4.8
115
115
  signing_key:
116
116
  specification_version: 4
117
117
  summary: CPuts - CustomPuts