nub 0.0.57 → 0.0.59

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: 8ce123bdfd67999eff41bd51cf0fb9f495e7ca3905a0943407291a2be9cff5d7
4
- data.tar.gz: 14c438fe160de88062825296ef1c2a212b926c78e1608c8e99b965d640d850a2
3
+ metadata.gz: d44b3ec64a04d2f92ed1f47ea2cea94cb61cdbf910597a68e33264fc7a08507a
4
+ data.tar.gz: 5adcda6c4ddeedaf96c855e58c41caf84072d246a136038b8f1cc492d9ca14b8
5
5
  SHA512:
6
- metadata.gz: c833de5c3599e0695376d0bed75366ae12f44349a0854cbc7d354ec0467ad15b16630859ab25be563fa74cb00a91021f3299b3aa688046185c1782013ab50ef9
7
- data.tar.gz: 69fb2df991e50a62c18033d12c30af8ded19305f7e41a5d00411c536eac98215965326fe79d21fa65514ba346876c077026681830e6685497c61f4e456d5b313
6
+ metadata.gz: 556d332bb10b0f37ab55f2a53af5b951408928ecc63d3215cc2d4a4216b0c3dc6fcc6d5c9a2770c6a4de61f7c2cddfc22b0f438bbd9757c223308e64d9d180f2
7
+ data.tar.gz: fb5d7e41fdb4488e88cdc755f0681da35706eeacf9acef2ce8cc02760f659e01b2f6c47e006dc3d2acd57b4d308a170b1ddeb4c16c30bdc75467d714ae71189a
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # ruby-nub
2
2
  Collection of ruby utils I've used in several of my projects and wanted re-usable
3
3
 
4
- [![Build Status](https://travis-ci.org/phR0ze/ruby-nub.svg)](https://travis-ci.org/phR0ze/ruby-nub)
4
+ [![Build Status](https://travis-ci.org/phR0ze/ruby-nub.svg)](https://travis-ci.org/phR0ze/ruby-nub&branch=master)
5
5
  [![Gem Version](https://badge.fury.io/rb/nub.svg)](https://badge.fury.io/rb/nub)
6
6
  [![Coverage Status](https://coveralls.io/repos/github/phR0ze/ruby-nub/badge.svg?branch=master)](https://coveralls.io/github/phR0ze/ruby-nub?branch=master)
7
7
  [![Dependency Status](https://beta.gemnasium.com/badges/github.com/phR0ze/ruby-nub.svg)](https://beta.gemnasium.com/projects/github.com/phR0ze/ruby-nub)
@@ -0,0 +1,46 @@
1
+ #MIT License
2
+ #Copyright (c) 2018 phR0ze
3
+ #
4
+ #Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ #of this software and associated documentation files (the "Software"), to deal
6
+ #in the Software without restriction, including without limitation the rights
7
+ #to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ #copies of the Software, and to permit persons to whom the Software is
9
+ #furnished to do so, subject to the following conditions:
10
+ #
11
+ #The above copyright notice and this permission notice shall be included in all
12
+ #copies or substantial portions of the Software.
13
+ #
14
+ #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ #IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ #FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ #AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ #LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ #OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ #SOFTWARE.
21
+
22
+ require 'fileutils'
23
+
24
+ # Monkey patch FileUtils with some useful methods
25
+ module FileUtils
26
+
27
+ # Check copyright and update if required
28
+ # @param path [String] path of the file to update
29
+ # @param copyright [String] copyright match string e.g. Copyright (c)
30
+ def update_copyright(path, copyright, year)
31
+ modify(path){|line|
32
+ if line =~ /##{Regexp.quote(copyright)}/
33
+ year = line[/##{Regexp.quote(copyright)}\s+((\d{4}\s)|(\d{4}-\d{4})).*/, 1].strip
34
+ if year.include?("-")
35
+ years = year.split("-")
36
+ line.gsub!(year, "#{years.first}-#{curr_year}") if years.last != curr_year
37
+ else
38
+ prev_year = year == curr_year.to_s ? year.to_i - 1 : year
39
+ line.gsub!(year.to_s, "#{prev_year}-#{curr_year}")
40
+ end
41
+ end
42
+ }
43
+ end
44
+ end
45
+
46
+ # vim: ft=ruby:ts=2:sw=2:sts=2
data/lib/nub/module.rb ADDED
@@ -0,0 +1,76 @@
1
+ #MIT License
2
+ #Copyright (c) 2018 phR0ze
3
+ #
4
+ #Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ #of this software and associated documentation files (the "Software"), to deal
6
+ #in the Software without restriction, including without limitation the rights
7
+ #to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ #copies of the Software, and to permit persons to whom the Software is
9
+ #furnished to do so, subject to the following conditions:
10
+ #
11
+ #The above copyright notice and this permission notice shall be included in all
12
+ #copies or substantial portions of the Software.
13
+ #
14
+ #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ #IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ #FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ #AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ #LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ #OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ #SOFTWARE.
21
+
22
+ class Module
23
+
24
+ # Leveraged mattr_reader, mattr_writer, mattr_accessor from rails project on github
25
+ # MIT license https://opensource.org/licenses/MIT
26
+ # https://github.com/rails/rails/blob/2-1-stable/activesupport/lib/active_support/core_ext/module/attribute_accessors.rb
27
+ #
28
+ # Extends the module object with module and instance accessors for class attributes,
29
+ # just like the native attr* accessors for instance attributes.
30
+ #
31
+ # module AppConfiguration
32
+ # mattr_accessor :google_api_key
33
+ # self.google_api_key = "123456789"
34
+ # end
35
+ # AppConfiguration.google_api_key = "overriding the api key!"
36
+
37
+ # Create reader class/module methods for property
38
+ # @param syms [Array(Symbol)] splat array of property names
39
+ def mattr_reader(*syms)
40
+ syms.each{|sym|
41
+ next if sym.is_a?(Hash)
42
+ class_eval(<<-EOS, __FILE__, __LINE__)
43
+ @@#{sym} = nil if !defined?(@@#{sym})
44
+
45
+ def self.#{sym}
46
+ @@#{sym}
47
+ end
48
+ def #{sym}
49
+ @@#{sym}
50
+ end
51
+ EOS
52
+ }
53
+ end
54
+
55
+ # Create reader class/module methods for property
56
+ # @param syms [Array(Symbol)] splat array of property names
57
+ def mattr_writer(*syms)
58
+ syms.each{|sym|
59
+ class_eval(<<-EOS, __FILE__, __LINE__)
60
+ @@#{sym} = nil if !defined?(@@#{sym})
61
+
62
+ def self.#{sym}=(obj)
63
+ @@#{sym} = obj
64
+ end
65
+ def #{sym}=(obj)
66
+ @@#{sym} = obj
67
+ end
68
+ EOS
69
+ }
70
+ end
71
+
72
+ def mattr_accessor(*syms)
73
+ mattr_reader(*syms)
74
+ mattr_writer(*syms)
75
+ end
76
+ end
data/lib/nub.rb CHANGED
@@ -24,7 +24,9 @@
24
24
  module Nub
25
25
  require 'nub/commander'
26
26
  require 'nub/config'
27
+ require 'nub/fileutils'
27
28
  require 'nub/log'
29
+ require 'nub/module'
28
30
  require 'nub/net'
29
31
  require 'nub/string'
30
32
  require 'nub/thread_comm'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.57
4
+ version: 0.0.59
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrick Crummett
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-07 00:00:00.000000000 Z
11
+ date: 2018-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -105,7 +105,9 @@ files:
105
105
  - lib/nub.rb
106
106
  - lib/nub/commander.rb
107
107
  - lib/nub/config.rb
108
+ - lib/nub/fileutils.rb
108
109
  - lib/nub/log.rb
110
+ - lib/nub/module.rb
109
111
  - lib/nub/net.rb
110
112
  - lib/nub/string.rb
111
113
  - lib/nub/sys.rb