dtk-common-core 0.8.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +13 -5
- data/dtk-common-core.gemspec +1 -1
- data/lib/auxiliary.rb +1 -1
- data/lib/dtk-common-core/version.rb +3 -3
- data/lib/errors/errors.rb +1 -1
- data/lib/errors/rest_error.rb +59 -59
- data/lib/hash_object.rb +50 -49
- data/lib/log.rb +37 -37
- data/lib/response.rb +1 -1
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ODQzZGUxMmM4NzgyZTdlODE0MDVjYWM3NTJmOTcyZmU3Y2ZiN2Q2MQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZDM4OGVkYTZmNzg1MGUyYzYyMDZmMWUwMGViZTJiZTRkMzczNGRhMw==
|
5
7
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ODhmYWJiMTZiYzJmN2QxYWI4ZDZmMTkzMWJiM2IzYmZiN2I3OTFiM2RhNWJj
|
10
|
+
ZmVkMTk0YzZjZjFmZTQ5MDM5NzMwZmY0MzlhZThhOTdiNDc5MWQwMDM3MTEz
|
11
|
+
YmQ1MDlhODQ4MzM4Y2M2NjU3ZGU2YmU4MzY4ZDc3YTRhMjk3NmI=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NjQ2ZGJiZTUyMjUwNGRjN2RhYzJjMWQ2MDM1ZjUwODMzNWZjY2VhNDZhODNm
|
14
|
+
OGZkMTk1ZTM1ODhkZTJmOWVkYjFlNzRkM2M3NjcwNmU0YzVhY2QzMzc2Nzcy
|
15
|
+
ZWVlOWZjZWYxZDU3MTFlNmE1NTdiM2Y2Y2IzOThhODgzNjUyOWQ=
|
data/dtk-common-core.gemspec
CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |gem|
|
|
7
7
|
gem.description = %q{DTK Common Core is a shared library used by several DTK components.}
|
8
8
|
gem.summary = %q{Common libraries used for DTK CLI client.}
|
9
9
|
gem.homepage = "https://github.com/rich-reactor8/dtk-common-repo"
|
10
|
-
gem.licenses = ["
|
10
|
+
gem.licenses = ["Apache-2.0"]
|
11
11
|
|
12
12
|
gem.files = `git ls-files`.split($\)
|
13
13
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
data/lib/auxiliary.rb
CHANGED
data/lib/errors/errors.rb
CHANGED
data/lib/errors/rest_error.rb
CHANGED
@@ -15,62 +15,62 @@
|
|
15
15
|
# See the License for the specific language governing permissions and
|
16
16
|
# limitations under the License.
|
17
17
|
#
|
18
|
-
#TODO: should have a Common namespace put in after DTK
|
19
|
-
#When creating these objects, an internal errro class is passed to the creation functions
|
20
|
-
module DTK
|
21
|
-
class RestError
|
22
|
-
def self.create(err)
|
23
|
-
if RestUsageError.match?(err)
|
24
|
-
RestUsageError.new(err)
|
25
|
-
elsif NotFound.match?(err)
|
26
|
-
NotFound.new(err)
|
27
|
-
else
|
28
|
-
Internal.new(err)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
def initialize(err)
|
32
|
-
@code = nil
|
33
|
-
@message = nil
|
34
|
-
end
|
35
|
-
def hash_form()
|
36
|
-
{:code => code||:error, :message => message||''}
|
37
|
-
end
|
38
|
-
private
|
39
|
-
attr_reader :code, :message
|
40
|
-
public
|
41
|
-
#its either its a usage or and internal (application error) bug
|
42
|
-
class Internal < RestError
|
43
|
-
def hash_form()
|
44
|
-
super.merge(:internal => true)
|
45
|
-
end
|
46
|
-
private
|
47
|
-
def initialize(err)
|
48
|
-
super
|
49
|
-
@message = "#{err.to_s} (#{err.backtrace.first})"
|
50
|
-
end
|
51
|
-
end
|
52
|
-
class RestUsageError < RestError
|
53
|
-
def initialize(err)
|
54
|
-
super
|
55
|
-
@message = err.to_s
|
56
|
-
end
|
57
|
-
def self.match?(err)
|
58
|
-
err.kind_of?(ErrorUsage)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
class NotFound < RestUsageError
|
62
|
-
def self.match?(err)
|
63
|
-
err.kind_of?(::NoMethodError) and is_controller_method(err)
|
64
|
-
end
|
65
|
-
def initialize(err)
|
66
|
-
super
|
67
|
-
@code = :not_found
|
68
|
-
@message = "'#{err.name}' was not found"
|
69
|
-
end
|
70
|
-
private
|
71
|
-
def self.is_controller_method(err)
|
72
|
-
err.to_s =~ /#<XYZ::.+Controller:/
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
18
|
+
#TODO: should have a Common namespace put in after DTK
|
19
|
+
#When creating these objects, an internal errro class is passed to the creation functions
|
20
|
+
module DTK
|
21
|
+
class RestError
|
22
|
+
def self.create(err)
|
23
|
+
if RestUsageError.match?(err)
|
24
|
+
RestUsageError.new(err)
|
25
|
+
elsif NotFound.match?(err)
|
26
|
+
NotFound.new(err)
|
27
|
+
else
|
28
|
+
Internal.new(err)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
def initialize(err)
|
32
|
+
@code = nil
|
33
|
+
@message = nil
|
34
|
+
end
|
35
|
+
def hash_form()
|
36
|
+
{:code => code||:error, :message => message||''}
|
37
|
+
end
|
38
|
+
private
|
39
|
+
attr_reader :code, :message
|
40
|
+
public
|
41
|
+
#its either its a usage or and internal (application error) bug
|
42
|
+
class Internal < RestError
|
43
|
+
def hash_form()
|
44
|
+
super.merge(:internal => true)
|
45
|
+
end
|
46
|
+
private
|
47
|
+
def initialize(err)
|
48
|
+
super
|
49
|
+
@message = "#{err.to_s} (#{err.backtrace.first})"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
class RestUsageError < RestError
|
53
|
+
def initialize(err)
|
54
|
+
super
|
55
|
+
@message = err.to_s
|
56
|
+
end
|
57
|
+
def self.match?(err)
|
58
|
+
err.kind_of?(ErrorUsage)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
class NotFound < RestUsageError
|
62
|
+
def self.match?(err)
|
63
|
+
err.kind_of?(::NoMethodError) and is_controller_method(err)
|
64
|
+
end
|
65
|
+
def initialize(err)
|
66
|
+
super
|
67
|
+
@code = :not_found
|
68
|
+
@message = "'#{err.name}' was not found"
|
69
|
+
end
|
70
|
+
private
|
71
|
+
def self.is_controller_method(err)
|
72
|
+
err.to_s =~ /#<XYZ::.+Controller:/
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
data/lib/hash_object.rb
CHANGED
@@ -15,52 +15,53 @@
|
|
15
15
|
# See the License for the specific language governing permissions and
|
16
16
|
# limitations under the License.
|
17
17
|
#
|
18
|
-
module DTK
|
19
|
-
module Common
|
20
|
-
class SimpleHashObject < Hash
|
21
|
-
def initialize(initial_val=nil,&block)
|
22
|
-
block ? super(&block) : super()
|
23
|
-
if initial_val
|
24
|
-
replace(initial_val)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
# require 'active_support/ordered_hash'
|
30
|
-
# class SimpleOrderedHash < ::ActiveSupport::OrderedHash
|
31
|
-
class SimpleOrderedHash < Hash
|
32
|
-
def initialize(elements=[])
|
33
|
-
super()
|
34
|
-
elements = [elements] unless elements.kind_of?(Array)
|
35
|
-
elements.each{|el|self[el.keys.first] = el.values.first}
|
36
|
-
end
|
37
|
-
|
38
|
-
#set unless value is nill
|
39
|
-
def set_unless_nil(k,v)
|
40
|
-
self[k] = v unless v.nil?
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
class PrettyPrintHash < SimpleOrderedHash
|
45
|
-
#field with '?' suffix means optioanlly add depending on whether name present and non-null in source
|
46
|
-
#if block is given then apply to source[name] rather than returning just source[name]
|
47
|
-
def add(model_object,*keys,&block)
|
48
|
-
keys.each do |key|
|
49
|
-
#if marked as optional skip if not present
|
50
|
-
if key.to_s =~ /(^.+)\?$/
|
51
|
-
key = $1.to_sym
|
52
|
-
next unless model_object[key]
|
53
|
-
end
|
54
|
-
#special treatment of :id
|
55
|
-
val = (key == :id ? model_object.id : model_object[key])
|
56
|
-
self[key] = (block ? block.call(val) : val)
|
57
|
-
end
|
58
|
-
self
|
59
|
-
end
|
60
|
-
|
61
|
-
def slice(*keys)
|
62
|
-
keys.inject(self.class.new){|h,k|h.merge(k => self[k])}
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
18
|
+
module DTK
|
19
|
+
module Common
|
20
|
+
class SimpleHashObject < Hash
|
21
|
+
def initialize(initial_val=nil,&block)
|
22
|
+
block ? super(&block) : super()
|
23
|
+
if initial_val
|
24
|
+
replace(initial_val)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# require 'active_support/ordered_hash'
|
30
|
+
# class SimpleOrderedHash < ::ActiveSupport::OrderedHash
|
31
|
+
class SimpleOrderedHash < Hash
|
32
|
+
def initialize(elements=[])
|
33
|
+
super()
|
34
|
+
elements = [elements] unless elements.kind_of?(Array)
|
35
|
+
elements.each{|el|self[el.keys.first] = el.values.first}
|
36
|
+
end
|
37
|
+
|
38
|
+
#set unless value is nill
|
39
|
+
def set_unless_nil(k,v)
|
40
|
+
self[k] = v unless v.nil?
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
class PrettyPrintHash < SimpleOrderedHash
|
45
|
+
#field with '?' suffix means optioanlly add depending on whether name present and non-null in source
|
46
|
+
#if block is given then apply to source[name] rather than returning just source[name]
|
47
|
+
def add(model_object,*keys,&block)
|
48
|
+
keys.each do |key|
|
49
|
+
#if marked as optional skip if not present
|
50
|
+
if key.to_s =~ /(^.+)\?$/
|
51
|
+
key = $1.to_sym
|
52
|
+
next unless model_object[key]
|
53
|
+
end
|
54
|
+
#special treatment of :id
|
55
|
+
val = (key == :id ? model_object.id : model_object[key])
|
56
|
+
self[key] = (block ? block.call(val) : val)
|
57
|
+
end
|
58
|
+
self
|
59
|
+
end
|
60
|
+
|
61
|
+
def slice(*keys)
|
62
|
+
keys.inject(self.class.new){|h,k|h.merge(k => self[k])}
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
data/lib/log.rb
CHANGED
@@ -15,40 +15,40 @@
|
|
15
15
|
# See the License for the specific language governing permissions and
|
16
16
|
# limitations under the License.
|
17
17
|
#
|
18
|
-
#TODO: bring in a production quality ruby logging capability that gets wrapped here
|
19
|
-
#TODO: would put this in config
|
20
|
-
module DTK
|
21
|
-
module Log
|
22
|
-
Config = Hash.new
|
23
|
-
Config[:print_time] = false
|
24
|
-
Config[:print_method] = false
|
25
|
-
|
26
|
-
def self.info(msg, out = $stdout)
|
27
|
-
out << "info: "
|
28
|
-
out << format(msg)
|
29
|
-
end
|
30
|
-
def self.debug(msg, out = $stdout)
|
31
|
-
out << "debug: "
|
32
|
-
out << format(msg)
|
33
|
-
end
|
34
|
-
def self.error(msg, out = $stdout)
|
35
|
-
out << "error: "
|
36
|
-
out << format(msg)
|
37
|
-
end
|
38
|
-
def self.info_pp(obj, out = $stdout)
|
39
|
-
out << Aux::pp_form(obj)
|
40
|
-
end
|
41
|
-
def self.debug_pp(obj, out = $stdout)
|
42
|
-
out << Aux::pp_form(obj)
|
43
|
-
obj
|
44
|
-
end
|
45
|
-
private
|
46
|
-
def self.format(msg)
|
47
|
-
ret = String.new
|
48
|
-
ret << "#{Time.now}: " if Config[:print_time]
|
49
|
-
ret << "in fn: #{this_parent_method}: " if Config[:print_method]
|
50
|
-
ret << msg
|
51
|
-
ret << "\n"
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
18
|
+
#TODO: bring in a production quality ruby logging capability that gets wrapped here
|
19
|
+
#TODO: would put this in config
|
20
|
+
module DTK
|
21
|
+
module Log
|
22
|
+
Config = Hash.new
|
23
|
+
Config[:print_time] = false
|
24
|
+
Config[:print_method] = false
|
25
|
+
|
26
|
+
def self.info(msg, out = $stdout)
|
27
|
+
out << "info: "
|
28
|
+
out << format(msg)
|
29
|
+
end
|
30
|
+
def self.debug(msg, out = $stdout)
|
31
|
+
out << "debug: "
|
32
|
+
out << format(msg)
|
33
|
+
end
|
34
|
+
def self.error(msg, out = $stdout)
|
35
|
+
out << "error: "
|
36
|
+
out << format(msg)
|
37
|
+
end
|
38
|
+
def self.info_pp(obj, out = $stdout)
|
39
|
+
out << Aux::pp_form(obj)
|
40
|
+
end
|
41
|
+
def self.debug_pp(obj, out = $stdout)
|
42
|
+
out << Aux::pp_form(obj)
|
43
|
+
obj
|
44
|
+
end
|
45
|
+
private
|
46
|
+
def self.format(msg)
|
47
|
+
ret = String.new
|
48
|
+
ret << "#{Time.now}: " if Config[:print_time]
|
49
|
+
ret << "in fn: #{this_parent_method}: " if Config[:print_method]
|
50
|
+
ret << msg
|
51
|
+
ret << "\n"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/lib/response.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dtk-common-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rich PELAVIN
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-03-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -31,8 +31,8 @@ executables: []
|
|
31
31
|
extensions: []
|
32
32
|
extra_rdoc_files: []
|
33
33
|
files:
|
34
|
-
-
|
35
|
-
-
|
34
|
+
- .gitignore
|
35
|
+
- .license_header
|
36
36
|
- Gemfile
|
37
37
|
- LICENSE
|
38
38
|
- README.md
|
@@ -49,7 +49,7 @@ files:
|
|
49
49
|
- lib/response.rb
|
50
50
|
homepage: https://github.com/rich-reactor8/dtk-common-repo
|
51
51
|
licenses:
|
52
|
-
-
|
52
|
+
- Apache-2.0
|
53
53
|
metadata: {}
|
54
54
|
post_install_message:
|
55
55
|
rdoc_options: []
|
@@ -57,17 +57,17 @@ require_paths:
|
|
57
57
|
- lib
|
58
58
|
required_ruby_version: !ruby/object:Gem::Requirement
|
59
59
|
requirements:
|
60
|
-
- -
|
60
|
+
- - ! '>='
|
61
61
|
- !ruby/object:Gem::Version
|
62
62
|
version: '0'
|
63
63
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
64
|
requirements:
|
65
|
-
- -
|
65
|
+
- - ! '>='
|
66
66
|
- !ruby/object:Gem::Version
|
67
67
|
version: '0'
|
68
68
|
requirements: []
|
69
69
|
rubyforge_project:
|
70
|
-
rubygems_version: 2.4.
|
70
|
+
rubygems_version: 2.4.8
|
71
71
|
signing_key:
|
72
72
|
specification_version: 4
|
73
73
|
summary: Common libraries used for DTK CLI client.
|