locomotivecms_common 0.0.2 → 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 +4 -4
- data/.gitignore +2 -0
- data/.rspec +2 -0
- data/.travis.yml +0 -1
- data/Gemfile +7 -0
- data/Gemfile.lock +65 -11
- data/README.md +1 -9
- data/lib/locomotive/common/core_ext/boolean/false.rb +3 -0
- data/lib/locomotive/common/core_ext/boolean/true.rb +3 -0
- data/lib/locomotive/common/core_ext/hash.rb +39 -0
- data/lib/locomotive/common/core_ext/kernel.rb +14 -0
- data/lib/locomotive/common/core_ext/string.rb +37 -0
- data/lib/locomotive/common/core_ext.rb +5 -0
- data/lib/locomotive/common/exception.rb +0 -3
- data/lib/locomotive/common/logger.rb +7 -3
- data/lib/locomotive/common/version.rb +2 -2
- data/lib/locomotive/common.rb +6 -0
- data/locomotivecms_common.gemspec +5 -3
- data/spec/spec_helper.rb +14 -0
- data/spec/unit/core_ext/string_spec.rb +44 -0
- metadata +30 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c38419a91faf5987f3d4c79962c46e0ead0de7b6
|
4
|
+
data.tar.gz: 7e94cb9cc7289a2dab52dcabbbb7eb4eb22c0512
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 008e1108130856740226ff72c8715b0c4acb36b459dbec096e062895aae0c480f3d5e8b1079899cf0c5b4d8ea1f2cd41117ec172155f912e93bbcd30aa045c6d
|
7
|
+
data.tar.gz: 7e41e88b8844bda2512e1f6044bd6113f338a9dd54bc461a37af41e68d13f289076e26f50db628eac1a8122afa10ac4a24a4f9c35e02702c9eb1013b7a17796f
|
data/.rspec
ADDED
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
@@ -2,3 +2,10 @@ source 'https://rubygems.org'
|
|
2
2
|
|
3
3
|
# Specify your gem's dependencies in locomotivecms_common.gemspec
|
4
4
|
gemspec
|
5
|
+
|
6
|
+
group :test do
|
7
|
+
gem 'rspec', '~> 3.2.0'
|
8
|
+
|
9
|
+
gem 'codeclimate-test-reporter', '~> 0.4.7', require: false
|
10
|
+
gem 'coveralls', '~> 0.7.12', require: false
|
11
|
+
end
|
data/Gemfile.lock
CHANGED
@@ -1,29 +1,83 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
locomotivecms_common (0.0.
|
4
|
+
locomotivecms_common (0.0.3)
|
5
|
+
activesupport (~> 4.2.1)
|
5
6
|
colorize
|
7
|
+
stringex (~> 2.5.2)
|
6
8
|
|
7
9
|
GEM
|
8
10
|
remote: https://rubygems.org/
|
9
11
|
specs:
|
10
|
-
|
12
|
+
activesupport (4.2.1)
|
13
|
+
i18n (~> 0.7)
|
14
|
+
json (~> 1.7, >= 1.7.7)
|
15
|
+
minitest (~> 5.1)
|
16
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
17
|
+
tzinfo (~> 1.1)
|
18
|
+
codeclimate-test-reporter (0.4.7)
|
19
|
+
simplecov (>= 0.7.1, < 1.0.0)
|
20
|
+
colorize (0.7.5)
|
21
|
+
coveralls (0.7.12)
|
22
|
+
multi_json (~> 1.10)
|
23
|
+
rest-client (>= 1.6.8, < 2)
|
24
|
+
simplecov (~> 0.9.1)
|
25
|
+
term-ansicolor (~> 1.3)
|
26
|
+
thor (~> 0.19.1)
|
11
27
|
diff-lcs (1.2.5)
|
28
|
+
docile (1.1.5)
|
29
|
+
domain_name (0.5.23)
|
30
|
+
unf (>= 0.0.5, < 1.0.0)
|
31
|
+
http-cookie (1.0.2)
|
32
|
+
domain_name (~> 0.5)
|
33
|
+
i18n (0.7.0)
|
34
|
+
json (1.8.2)
|
35
|
+
mime-types (2.4.3)
|
36
|
+
minitest (5.5.1)
|
37
|
+
multi_json (1.11.0)
|
38
|
+
netrc (0.10.3)
|
12
39
|
rake (10.2.2)
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
rspec
|
18
|
-
|
19
|
-
|
20
|
-
|
40
|
+
rest-client (1.8.0)
|
41
|
+
http-cookie (>= 1.0.2, < 2.0)
|
42
|
+
mime-types (>= 1.16, < 3.0)
|
43
|
+
netrc (~> 0.7)
|
44
|
+
rspec (3.2.0)
|
45
|
+
rspec-core (~> 3.2.0)
|
46
|
+
rspec-expectations (~> 3.2.0)
|
47
|
+
rspec-mocks (~> 3.2.0)
|
48
|
+
rspec-core (3.2.2)
|
49
|
+
rspec-support (~> 3.2.0)
|
50
|
+
rspec-expectations (3.2.0)
|
51
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
52
|
+
rspec-support (~> 3.2.0)
|
53
|
+
rspec-mocks (3.2.1)
|
54
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
55
|
+
rspec-support (~> 3.2.0)
|
56
|
+
rspec-support (3.2.2)
|
57
|
+
simplecov (0.9.2)
|
58
|
+
docile (~> 1.1.0)
|
59
|
+
multi_json (~> 1.0)
|
60
|
+
simplecov-html (~> 0.9.0)
|
61
|
+
simplecov-html (0.9.0)
|
62
|
+
stringex (2.5.2)
|
63
|
+
term-ansicolor (1.3.0)
|
64
|
+
tins (~> 1.0)
|
65
|
+
thor (0.19.1)
|
66
|
+
thread_safe (0.3.5)
|
67
|
+
tins (1.3.5)
|
68
|
+
tzinfo (1.2.2)
|
69
|
+
thread_safe (~> 0.1)
|
70
|
+
unf (0.1.4)
|
71
|
+
unf_ext
|
72
|
+
unf_ext (0.0.6)
|
21
73
|
|
22
74
|
PLATFORMS
|
23
75
|
ruby
|
24
76
|
|
25
77
|
DEPENDENCIES
|
26
78
|
bundler (~> 1.5)
|
79
|
+
codeclimate-test-reporter (~> 0.4.7)
|
80
|
+
coveralls (~> 0.7.12)
|
27
81
|
locomotivecms_common!
|
28
82
|
rake (~> 10.1)
|
29
|
-
rspec (~> 2.
|
83
|
+
rspec (~> 3.2.0)
|
data/README.md
CHANGED
@@ -1,14 +1,6 @@
|
|
1
1
|
# LocomotiveCMS Common
|
2
2
|
|
3
|
-
[](https://codeclimate.com/github/locomotivecms/common)
|
6
|
-
|
7
|
-
[](https://gemnasium.com/locomotivecms/common)
|
8
|
-
|
9
|
-
[](https://travis-ci.org/locomotivecms/common) (Travis CI)
|
10
|
-
|
11
|
-
[](https://coveralls.io/r/locomotivecms/common)
|
3
|
+
[](http://badge.fury.io/rb/locomotivecms_common) [](https://codeclimate.com/github/locomotivecms/common) [](https://gemnasium.com/locomotivecms/common) [](https://travis-ci.org/locomotivecms/common) [](https://coveralls.io/r/locomotivecms/common)
|
12
4
|
|
13
5
|
# Description
|
14
6
|
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# Big thanks to Tim Ruffles (https://github.com/timruffles)
|
2
|
+
# https://gist.github.com/timruffles/2780508
|
3
|
+
module HashConverter
|
4
|
+
class << self
|
5
|
+
|
6
|
+
def to_underscore(hash)
|
7
|
+
convert(hash, :underscore)
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_string(hash)
|
11
|
+
convert(hash, :to_s)
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_sym(hash)
|
15
|
+
convert(hash, :to_sym)
|
16
|
+
end
|
17
|
+
|
18
|
+
# FIXME: not sure it will be ever needed
|
19
|
+
# def to_camel_case hash
|
20
|
+
# convert hash, :camelize, :lower
|
21
|
+
# end
|
22
|
+
|
23
|
+
def convert(obj, *method)
|
24
|
+
case obj
|
25
|
+
when Hash
|
26
|
+
obj.inject({}) do |h, (k,v)|
|
27
|
+
v = convert(v, *method)
|
28
|
+
h[k.send(*method)] = v
|
29
|
+
h
|
30
|
+
end
|
31
|
+
when Array
|
32
|
+
obj.map { |m| convert(m, *method) }
|
33
|
+
else
|
34
|
+
obj
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Kernel
|
2
|
+
|
3
|
+
def require_relative_all(paths, sub = nil)
|
4
|
+
main_path = File.dirname(caller.first.sub(/:\d+$/, ''))
|
5
|
+
main_path = File.join(main_path, sub) if sub
|
6
|
+
|
7
|
+
[*paths].each do |path|
|
8
|
+
Dir[File.join(main_path, path, '*.rb')].each { |file| require file }
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
unless String.public_instance_methods.include?(:to_bool)
|
2
|
+
class String
|
3
|
+
|
4
|
+
def to_bool
|
5
|
+
return true if self == true || self =~ (/(true|t|yes|y|1)$/i)
|
6
|
+
return false if self == false || self.blank? || self =~ (/(false|f|no|n|0)$/i)
|
7
|
+
|
8
|
+
raise ArgumentError.new("invalid value for Boolean: \"#{self}\"")
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
unless String.public_instance_methods.include?(:permalink)
|
15
|
+
require 'stringex'
|
16
|
+
|
17
|
+
class String
|
18
|
+
|
19
|
+
def permalink(underscore = false)
|
20
|
+
# if the slug includes one "_" at least, we consider that the "_" is used instead of "-".
|
21
|
+
_permalink = if !self.index('_').nil?
|
22
|
+
self.to_url(replace_whitespace_with: '_')
|
23
|
+
else
|
24
|
+
self.to_url
|
25
|
+
end
|
26
|
+
|
27
|
+
underscore ? _permalink.underscore : _permalink
|
28
|
+
end
|
29
|
+
|
30
|
+
def permalink!(underscore = false)
|
31
|
+
replace(self.permalink(underscore))
|
32
|
+
end
|
33
|
+
|
34
|
+
alias :parameterize! :permalink!
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
@@ -16,7 +16,7 @@ module Locomotive
|
|
16
16
|
# @param[ optional ] [ String ] path The path to the log file, full path with log file name
|
17
17
|
# Sample /home/locomotivecms/log/server.log (default: nil => Stdout)
|
18
18
|
#
|
19
|
-
def setup
|
19
|
+
def setup(log_file_full_path = nil)
|
20
20
|
require 'logger'
|
21
21
|
|
22
22
|
output = begin
|
@@ -39,7 +39,7 @@ module Locomotive
|
|
39
39
|
@@instance ||= self.new
|
40
40
|
end
|
41
41
|
|
42
|
-
def self.setup
|
42
|
+
def self.setup(*args)
|
43
43
|
if args.size > 1
|
44
44
|
puts "[DEPRECATION] Logger.setup(path, stdout=false) is deprecated. " \
|
45
45
|
"Please use Logger.setup(log_file_full_path) instead, " \
|
@@ -48,6 +48,10 @@ module Locomotive
|
|
48
48
|
self.instance.setup args.first
|
49
49
|
end
|
50
50
|
|
51
|
+
def self.close
|
52
|
+
self.instance.logger.close
|
53
|
+
end
|
54
|
+
|
51
55
|
class << self
|
52
56
|
%w(debug info warn error fatal unknown).each do |name|
|
53
57
|
define_method(name) do |message|
|
@@ -58,7 +62,7 @@ module Locomotive
|
|
58
62
|
|
59
63
|
private
|
60
64
|
|
61
|
-
def log_file_path
|
65
|
+
def log_file_path(log_file_full_path)
|
62
66
|
if File.directory? log_file_full_path
|
63
67
|
puts "[DEPRECATION] Please use fully log file path like: /home/locomotivecms/log/server.log"
|
64
68
|
File.expand_path(File.join(log_file_full_path, 'log', 'locomotivecms.log'))
|
data/lib/locomotive/common.rb
CHANGED
@@ -1,9 +1,15 @@
|
|
1
1
|
require_relative 'common/version'
|
2
|
+
require_relative 'common/core_ext'
|
2
3
|
require_relative 'common/logger'
|
3
4
|
require_relative 'common/exception'
|
4
5
|
require_relative 'common/notifier'
|
5
6
|
require_relative 'common/configuration'
|
6
7
|
|
8
|
+
require 'active_support'
|
9
|
+
require 'active_support/concern'
|
10
|
+
require 'active_support/deprecation'
|
11
|
+
require 'active_support/core_ext'
|
12
|
+
|
7
13
|
module Locomotive
|
8
14
|
module Common
|
9
15
|
class << self
|
@@ -16,10 +16,12 @@ Gem::Specification.new do |spec|
|
|
16
16
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
17
17
|
spec.require_paths = ['lib']
|
18
18
|
|
19
|
-
spec.add_development_dependency 'bundler',
|
20
|
-
spec.add_development_dependency 'rake',
|
21
|
-
spec.add_development_dependency 'rspec', '~> 2.14'
|
19
|
+
spec.add_development_dependency 'bundler', '~> 1.5'
|
20
|
+
spec.add_development_dependency 'rake', '~> 10.1'
|
22
21
|
|
22
|
+
spec.add_dependency 'activesupport', '~> 4.2.1'
|
23
|
+
spec.add_dependency 'stringex', '~> 2.5.2'
|
23
24
|
spec.add_dependency 'colorize'
|
25
|
+
|
24
26
|
spec.required_ruby_version = '~> 2.0'
|
25
27
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
require 'codeclimate-test-reporter'
|
3
|
+
require 'coveralls'
|
4
|
+
|
5
|
+
SimpleCov.start do
|
6
|
+
formatter SimpleCov::Formatter::MultiFormatter[
|
7
|
+
SimpleCov::Formatter::HTMLFormatter,
|
8
|
+
CodeClimate::TestReporter::Formatter,
|
9
|
+
Coveralls::SimpleCov::Formatter
|
10
|
+
]
|
11
|
+
|
12
|
+
add_filter 'spec/'
|
13
|
+
end
|
14
|
+
|
1
15
|
require 'rubygems'
|
2
16
|
require 'bundler/setup'
|
3
17
|
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe String do
|
4
|
+
|
5
|
+
describe '#permalink!' do
|
6
|
+
|
7
|
+
let(:string) { 'foo bar' }
|
8
|
+
|
9
|
+
before { string.permalink! }
|
10
|
+
|
11
|
+
it { expect(string).to eq 'foo-bar' }
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#to_bool' do
|
16
|
+
|
17
|
+
subject { string.to_bool }
|
18
|
+
|
19
|
+
describe 'true values' do
|
20
|
+
|
21
|
+
%w(true t yes y 1).each do |val|
|
22
|
+
let(:string) { val }
|
23
|
+
it { is_expected.to eq true }
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
describe 'false values' do
|
29
|
+
|
30
|
+
(%w(false f no n 0) + ['']).each do |val|
|
31
|
+
let(:string) { val }
|
32
|
+
it { is_expected.to eq false }
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
describe 'no truthy or falsy' do
|
38
|
+
let(:string) { 'foo' }
|
39
|
+
it { expect { subject }.to raise_error(%(invalid value for Boolean: "foo")) }
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: locomotivecms_common
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Didier Lafforgue
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2015-03-31 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|
@@ -41,19 +41,33 @@ dependencies:
|
|
41
41
|
- !ruby/object:Gem::Version
|
42
42
|
version: '10.1'
|
43
43
|
- !ruby/object:Gem::Dependency
|
44
|
-
name:
|
44
|
+
name: activesupport
|
45
45
|
requirement: !ruby/object:Gem::Requirement
|
46
46
|
requirements:
|
47
47
|
- - "~>"
|
48
48
|
- !ruby/object:Gem::Version
|
49
|
-
version:
|
50
|
-
type: :
|
49
|
+
version: 4.2.1
|
50
|
+
type: :runtime
|
51
|
+
prerelease: false
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - "~>"
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 4.2.1
|
57
|
+
- !ruby/object:Gem::Dependency
|
58
|
+
name: stringex
|
59
|
+
requirement: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - "~>"
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: 2.5.2
|
64
|
+
type: :runtime
|
51
65
|
prerelease: false
|
52
66
|
version_requirements: !ruby/object:Gem::Requirement
|
53
67
|
requirements:
|
54
68
|
- - "~>"
|
55
69
|
- !ruby/object:Gem::Version
|
56
|
-
version:
|
70
|
+
version: 2.5.2
|
57
71
|
- !ruby/object:Gem::Dependency
|
58
72
|
name: colorize
|
59
73
|
requirement: !ruby/object:Gem::Requirement
|
@@ -78,6 +92,7 @@ extensions: []
|
|
78
92
|
extra_rdoc_files: []
|
79
93
|
files:
|
80
94
|
- ".gitignore"
|
95
|
+
- ".rspec"
|
81
96
|
- ".travis.yml"
|
82
97
|
- Gemfile
|
83
98
|
- Gemfile.lock
|
@@ -86,6 +101,12 @@ files:
|
|
86
101
|
- Rakefile
|
87
102
|
- lib/locomotive/common.rb
|
88
103
|
- lib/locomotive/common/configuration.rb
|
104
|
+
- lib/locomotive/common/core_ext.rb
|
105
|
+
- lib/locomotive/common/core_ext/boolean/false.rb
|
106
|
+
- lib/locomotive/common/core_ext/boolean/true.rb
|
107
|
+
- lib/locomotive/common/core_ext/hash.rb
|
108
|
+
- lib/locomotive/common/core_ext/kernel.rb
|
109
|
+
- lib/locomotive/common/core_ext/string.rb
|
89
110
|
- lib/locomotive/common/exception.rb
|
90
111
|
- lib/locomotive/common/logger.rb
|
91
112
|
- lib/locomotive/common/notifier.rb
|
@@ -94,6 +115,7 @@ files:
|
|
94
115
|
- locomotivecms_common.gemspec
|
95
116
|
- spec/locomotive/exception_spec.rb
|
96
117
|
- spec/spec_helper.rb
|
118
|
+
- spec/unit/core_ext/string_spec.rb
|
97
119
|
homepage: https://github.com/locomotivecms/common
|
98
120
|
licenses:
|
99
121
|
- MIT
|
@@ -114,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
114
136
|
version: '0'
|
115
137
|
requirements: []
|
116
138
|
rubyforge_project:
|
117
|
-
rubygems_version: 2.
|
139
|
+
rubygems_version: 2.4.5
|
118
140
|
signing_key:
|
119
141
|
specification_version: 4
|
120
142
|
summary: The LocomotiveCMS Common is a shared libraries package for all LocomotiveCMS
|
@@ -122,3 +144,4 @@ summary: The LocomotiveCMS Common is a shared libraries package for all Locomoti
|
|
122
144
|
test_files:
|
123
145
|
- spec/locomotive/exception_spec.rb
|
124
146
|
- spec/spec_helper.rb
|
147
|
+
- spec/unit/core_ext/string_spec.rb
|