pakyow-support 0.11.3 → 1.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/{pakyow-support/CHANGELOG.md → CHANGELOG.md} +4 -0
- data/LICENSE +4 -0
- data/{pakyow-support/README.md → README.md} +1 -2
- data/lib/pakyow/support/aargv.rb +25 -0
- data/lib/pakyow/support/bindable.rb +19 -0
- data/lib/pakyow/support/class_state.rb +49 -0
- data/lib/pakyow/support/cli/runner.rb +106 -0
- data/lib/pakyow/support/cli/style.rb +13 -0
- data/lib/pakyow/support/configurable/config.rb +153 -0
- data/lib/pakyow/support/configurable/setting.rb +52 -0
- data/lib/pakyow/support/configurable.rb +103 -0
- data/lib/pakyow/support/core_refinements/array/ensurable.rb +25 -0
- data/lib/pakyow/support/core_refinements/method/introspection.rb +21 -0
- data/lib/pakyow/support/core_refinements/proc/introspection.rb +21 -0
- data/lib/pakyow/support/core_refinements/string/normalization.rb +50 -0
- data/lib/pakyow/support/deep_dup.rb +61 -0
- data/lib/pakyow/support/deep_freeze.rb +82 -0
- data/lib/pakyow/support/definable.rb +242 -0
- data/lib/pakyow/support/dependencies.rb +61 -0
- data/lib/pakyow/support/extension.rb +82 -0
- data/lib/pakyow/support/hookable.rb +227 -0
- data/lib/pakyow/support/indifferentize.rb +183 -0
- data/lib/pakyow/support/inflector.rb +13 -0
- data/lib/pakyow/support/inspectable.rb +88 -0
- data/lib/pakyow/support/logging.rb +31 -0
- data/lib/pakyow/support/makeable/object_maker.rb +30 -0
- data/lib/pakyow/support/makeable/object_name.rb +45 -0
- data/lib/pakyow/support/makeable/object_namespace.rb +28 -0
- data/lib/pakyow/support/makeable.rb +117 -0
- data/lib/pakyow/support/message_verifier.rb +74 -0
- data/lib/pakyow/support/path_version.rb +21 -0
- data/lib/pakyow/support/pipeline/object.rb +41 -0
- data/lib/pakyow/support/pipeline.rb +335 -0
- data/lib/pakyow/support/safe_string.rb +60 -0
- data/lib/pakyow/support/serializer.rb +49 -0
- data/lib/pakyow/support/silenceable.rb +21 -0
- data/lib/pakyow/support/string_builder.rb +62 -0
- data/lib/pakyow/support.rb +1 -0
- metadata +107 -26
- data/pakyow-support/LICENSE +0 -20
- data/pakyow-support/lib/pakyow/support/aargv.rb +0 -15
- data/pakyow-support/lib/pakyow/support/array.rb +0 -9
- data/pakyow-support/lib/pakyow/support/dir.rb +0 -32
- data/pakyow-support/lib/pakyow/support/dup.rb +0 -23
- data/pakyow-support/lib/pakyow/support/file.rb +0 -5
- data/pakyow-support/lib/pakyow/support/hash.rb +0 -47
- data/pakyow-support/lib/pakyow/support/kernel.rb +0 -9
- data/pakyow-support/lib/pakyow/support/string.rb +0 -36
- data/pakyow-support/lib/pakyow/support.rb +0 -8
- data/pakyow-support/lib/pakyow-support.rb +0 -1
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Pakyow
|
4
|
+
module Support
|
5
|
+
# Silence warnings.
|
6
|
+
#
|
7
|
+
module Silenceable
|
8
|
+
def self.silence_warnings
|
9
|
+
original_verbosity = $VERBOSE
|
10
|
+
$VERBOSE = nil
|
11
|
+
yield
|
12
|
+
ensure
|
13
|
+
$VERBOSE = original_verbosity
|
14
|
+
end
|
15
|
+
|
16
|
+
def silence_warnings(&block)
|
17
|
+
Silenceable.silence_warnings(&block)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "pakyow/support/safe_string"
|
4
|
+
|
5
|
+
module Pakyow
|
6
|
+
module Support
|
7
|
+
# Builds a string from a template.
|
8
|
+
#
|
9
|
+
class StringBuilder
|
10
|
+
include SafeStringHelpers
|
11
|
+
|
12
|
+
PATTERN = /{([^}]*)}/
|
13
|
+
|
14
|
+
def initialize(template, html_safe: false, &block)
|
15
|
+
@template, @html_safe, @block = template.to_s, html_safe, block
|
16
|
+
end
|
17
|
+
|
18
|
+
def build(**values)
|
19
|
+
@template.dup.tap do |working_template|
|
20
|
+
working_template.scan(PATTERN).each do |match|
|
21
|
+
value = if match[0].include?(".")
|
22
|
+
object, property = match[0].split(".").map(&:to_sym)
|
23
|
+
if object_value = get_value(object, values)
|
24
|
+
ensure_real_value(object_value)[property]
|
25
|
+
end
|
26
|
+
else
|
27
|
+
get_value(match[0].to_sym, values)
|
28
|
+
end
|
29
|
+
|
30
|
+
value = if @html_safe
|
31
|
+
ensure_html_safety(value)
|
32
|
+
else
|
33
|
+
value.to_s
|
34
|
+
end
|
35
|
+
|
36
|
+
working_template.gsub!("{#{match[0]}}", value)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def get_value(name, values)
|
44
|
+
if @block
|
45
|
+
@block.call(name)
|
46
|
+
elsif values.key?(name)
|
47
|
+
values[name]
|
48
|
+
else
|
49
|
+
nil
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def ensure_real_value(object_value)
|
54
|
+
if defined?(Pakyow::Data::Proxy) && object_value.is_a?(Pakyow::Data::Proxy)
|
55
|
+
object_value.one
|
56
|
+
else
|
57
|
+
object_value
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
# frozen_string_literal: true
|
metadata
CHANGED
@@ -1,69 +1,150 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pakyow-support
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0.rc1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bryan Powell
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-07-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: concurrent-ruby
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
20
|
-
type: :
|
19
|
+
version: '1.1'
|
20
|
+
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '1.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: dry-inflector
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.1'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.1'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pastel
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.7'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.7'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: tty-command
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.8'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.8'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: tty-spinner
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.9'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.9'
|
27
83
|
description: Supporting code for Pakyow
|
28
84
|
email: bryan@metabahn.com
|
29
85
|
executables: []
|
30
86
|
extensions: []
|
31
87
|
extra_rdoc_files: []
|
32
88
|
files:
|
33
|
-
-
|
34
|
-
-
|
35
|
-
-
|
36
|
-
-
|
37
|
-
-
|
38
|
-
-
|
39
|
-
-
|
40
|
-
-
|
41
|
-
-
|
42
|
-
-
|
43
|
-
-
|
44
|
-
-
|
45
|
-
-
|
46
|
-
|
89
|
+
- CHANGELOG.md
|
90
|
+
- LICENSE
|
91
|
+
- README.md
|
92
|
+
- lib/pakyow/support.rb
|
93
|
+
- lib/pakyow/support/aargv.rb
|
94
|
+
- lib/pakyow/support/bindable.rb
|
95
|
+
- lib/pakyow/support/class_state.rb
|
96
|
+
- lib/pakyow/support/cli/runner.rb
|
97
|
+
- lib/pakyow/support/cli/style.rb
|
98
|
+
- lib/pakyow/support/configurable.rb
|
99
|
+
- lib/pakyow/support/configurable/config.rb
|
100
|
+
- lib/pakyow/support/configurable/setting.rb
|
101
|
+
- lib/pakyow/support/core_refinements/array/ensurable.rb
|
102
|
+
- lib/pakyow/support/core_refinements/method/introspection.rb
|
103
|
+
- lib/pakyow/support/core_refinements/proc/introspection.rb
|
104
|
+
- lib/pakyow/support/core_refinements/string/normalization.rb
|
105
|
+
- lib/pakyow/support/deep_dup.rb
|
106
|
+
- lib/pakyow/support/deep_freeze.rb
|
107
|
+
- lib/pakyow/support/definable.rb
|
108
|
+
- lib/pakyow/support/dependencies.rb
|
109
|
+
- lib/pakyow/support/extension.rb
|
110
|
+
- lib/pakyow/support/hookable.rb
|
111
|
+
- lib/pakyow/support/indifferentize.rb
|
112
|
+
- lib/pakyow/support/inflector.rb
|
113
|
+
- lib/pakyow/support/inspectable.rb
|
114
|
+
- lib/pakyow/support/logging.rb
|
115
|
+
- lib/pakyow/support/makeable.rb
|
116
|
+
- lib/pakyow/support/makeable/object_maker.rb
|
117
|
+
- lib/pakyow/support/makeable/object_name.rb
|
118
|
+
- lib/pakyow/support/makeable/object_namespace.rb
|
119
|
+
- lib/pakyow/support/message_verifier.rb
|
120
|
+
- lib/pakyow/support/path_version.rb
|
121
|
+
- lib/pakyow/support/pipeline.rb
|
122
|
+
- lib/pakyow/support/pipeline/object.rb
|
123
|
+
- lib/pakyow/support/safe_string.rb
|
124
|
+
- lib/pakyow/support/serializer.rb
|
125
|
+
- lib/pakyow/support/silenceable.rb
|
126
|
+
- lib/pakyow/support/string_builder.rb
|
127
|
+
homepage: https://pakyow.org
|
47
128
|
licenses:
|
48
|
-
-
|
129
|
+
- LGPL-3.0
|
49
130
|
metadata: {}
|
50
131
|
post_install_message:
|
51
132
|
rdoc_options: []
|
52
133
|
require_paths:
|
53
|
-
-
|
134
|
+
- lib
|
54
135
|
required_ruby_version: !ruby/object:Gem::Requirement
|
55
136
|
requirements:
|
56
137
|
- - ">="
|
57
138
|
- !ruby/object:Gem::Version
|
58
|
-
version: 2.
|
139
|
+
version: 2.5.0
|
59
140
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
141
|
requirements:
|
61
|
-
- - "
|
142
|
+
- - ">"
|
62
143
|
- !ruby/object:Gem::Version
|
63
|
-
version:
|
144
|
+
version: 1.3.1
|
64
145
|
requirements: []
|
65
146
|
rubyforge_project:
|
66
|
-
rubygems_version: 2.
|
147
|
+
rubygems_version: 2.7.6
|
67
148
|
signing_key:
|
68
149
|
specification_version: 4
|
69
150
|
summary: Pakyow Support
|
data/pakyow-support/LICENSE
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
Copyright (c) 2014-2015 Bryan Powell
|
2
|
-
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
-
a copy of this software and associated documentation files (the
|
5
|
-
"Software"), to deal in the Software without restriction, including
|
6
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
-
permit persons to whom the Software is furnished to do so, subject to
|
9
|
-
the following conditions:
|
10
|
-
|
11
|
-
The above copyright notice and this permission notice shall be
|
12
|
-
included in all copies or substantial portions of the Software.
|
13
|
-
|
14
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -1,15 +0,0 @@
|
|
1
|
-
module Pakyow
|
2
|
-
class Aargv
|
3
|
-
def self.normalize(args, opts)
|
4
|
-
Hash[opts.map { |opt_name, opt_opts|
|
5
|
-
type, default = opt_opts
|
6
|
-
|
7
|
-
[opt_name, value_of_type(args, type) || default]
|
8
|
-
}.reject { |pair| pair[1].nil? }]
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.value_of_type(values, type)
|
12
|
-
values.find { |value| value.is_a?(type) }
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
class Dir
|
2
|
-
# visit dir, then all files in dir, then walk_dir each directory in dir
|
3
|
-
def self.walk(dir, &block)
|
4
|
-
yield dir
|
5
|
-
all = Dir.entries(dir)
|
6
|
-
partition = all.partition{|e| File.file?("#{dir}/#{e}")}
|
7
|
-
files = partition[0]
|
8
|
-
dirs = partition[1]
|
9
|
-
files.each{|f| yield "#{dir}/#{f}" unless f.start_with?(".")}
|
10
|
-
dirs.each{|d| walk("#{dir}/#{d}", &block) unless d.start_with?(".")}
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.print(dir)
|
14
|
-
puts "/#{dir}"
|
15
|
-
Dir.walk(dir) {|full_path|
|
16
|
-
path = full_path.gsub(Regexp.new("#{dir}\/?"), '')
|
17
|
-
next if path.empty?
|
18
|
-
|
19
|
-
prefix = "|"
|
20
|
-
path.scan(/\//).size.times do
|
21
|
-
prefix += " |"
|
22
|
-
end
|
23
|
-
|
24
|
-
path.gsub!(/^.*\//, '')
|
25
|
-
puts "#{prefix}-- #{path}"
|
26
|
-
}
|
27
|
-
end
|
28
|
-
|
29
|
-
def self.within_dir?(dir1, dir2)
|
30
|
-
(dir1.split('/') - dir2.split('/')).empty?
|
31
|
-
end
|
32
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
module Pakyow
|
2
|
-
module Utils
|
3
|
-
module Dup
|
4
|
-
UNCLONEABLE = [Symbol, Fixnum, NilClass, TrueClass, FalseClass]
|
5
|
-
def self.deep(value)
|
6
|
-
return value if UNCLONEABLE.include?(value.class)
|
7
|
-
|
8
|
-
if value.is_a?(Hash)
|
9
|
-
result = value.clone
|
10
|
-
value.each { |k, v| result[deep(k)] = deep(v) }
|
11
|
-
result
|
12
|
-
elsif value.is_a?(Array)
|
13
|
-
result = value.clone
|
14
|
-
result.clear
|
15
|
-
value.each{ |v| result << deep(v) }
|
16
|
-
result
|
17
|
-
else
|
18
|
-
value.clone
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
class Hash
|
2
|
-
def deep_merge(second)
|
3
|
-
merger = proc { |key, v1, v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2 }
|
4
|
-
self.merge(second, &merger)
|
5
|
-
end
|
6
|
-
|
7
|
-
def deep_merge!(second)
|
8
|
-
merger = proc { |key, v1, v2| Hash === v1 && Hash === v2 ? v1.merge!(v2, &merger) : v2 }
|
9
|
-
self.merge!(second, &merger)
|
10
|
-
end
|
11
|
-
|
12
|
-
# Creates an indifferent hash. This means that when indifferentized, this hash:
|
13
|
-
# { 'foo' => 'bar' }
|
14
|
-
#
|
15
|
-
# Can be accessed like this:
|
16
|
-
# { :foo => 'bar' }
|
17
|
-
#
|
18
|
-
def self.strhash(hash)
|
19
|
-
indifferentize(hash)
|
20
|
-
end
|
21
|
-
|
22
|
-
# Converts keys to symbols.
|
23
|
-
def self.symbolize_keys(hash)
|
24
|
-
Hash[hash.map{|(k,v)| [k.to_sym,v]}]
|
25
|
-
end
|
26
|
-
|
27
|
-
# Converts keys/values to symbols.
|
28
|
-
def self.symbolize(hash)
|
29
|
-
Hash[hash.map{|(k,v)| [k.to_sym,v.to_sym]}]
|
30
|
-
end
|
31
|
-
|
32
|
-
protected
|
33
|
-
|
34
|
-
# (see {strhash})
|
35
|
-
def self.indifferentize(hash)
|
36
|
-
hash.each_pair do |key, value|
|
37
|
-
hash[key] = indifferentize(value) if value.is_a? ::Hash
|
38
|
-
end
|
39
|
-
|
40
|
-
indifferent_hash.merge(hash)
|
41
|
-
end
|
42
|
-
|
43
|
-
# (see {strhash})
|
44
|
-
def self.indifferent_hash
|
45
|
-
Hash.new { |hash,key| hash[key.to_s] if Symbol === key }
|
46
|
-
end
|
47
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
class String
|
2
|
-
# split . seperated string at the last .
|
3
|
-
def self.split_at_last_dot(s)
|
4
|
-
split_index = s.rindex('.')
|
5
|
-
return s,nil unless split_index
|
6
|
-
left = s[0,split_index]
|
7
|
-
right = s[split_index+1,s.length-(split_index+1)]
|
8
|
-
return left,right
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.remove_route_vars(route_spec)
|
12
|
-
return unless route_spec
|
13
|
-
arr = route_spec.split('/')
|
14
|
-
new_arr = []
|
15
|
-
arr.each {|e| new_arr << e unless e[0,1] == ':'}
|
16
|
-
ret = new_arr.join('/')
|
17
|
-
return '/' if ret == ''
|
18
|
-
return ret
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.parse_path_from_caller(caller)
|
22
|
-
caller.match(/^(.+)(:?:\d+(:?:in `.+')?$)/)[1]
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.normalize_path(path)
|
26
|
-
return path if path.is_a?(Regexp)
|
27
|
-
|
28
|
-
path = path[1, path.length - 1] if path[0, 1] == '/'
|
29
|
-
path = path[0, path.length - 1] if path[path.length - 1, 1] == '/'
|
30
|
-
path
|
31
|
-
end
|
32
|
-
|
33
|
-
def self.capitalize(string)
|
34
|
-
string.slice(0,1).capitalize + string.slice(1..-1)
|
35
|
-
end
|
36
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
require 'pakyow/support'
|