pakyow-support 0.9.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a98fdf0fbd99d1a691a4f029631a53b078508ace
4
+ data.tar.gz: efca31e4b9926e70d6002e97d4bc1f7d3ed25083
5
+ SHA512:
6
+ metadata.gz: 737331b370775737cd8f620e26881c205b8051682fb691e982c4e321a03f4aff97bb017e7340a02582c4f4c95e5d2e1eaf898aa63317e62a5ade5da5786d6fae
7
+ data.tar.gz: f255e406984ba59ef78d774baa2b6c758c1d8965697111c41ae4841fd44495688d902e81ffa41dccf4990a475a2b99b3d65f6e556692e50022ef0567893a29c3
@@ -0,0 +1,3 @@
1
+ = 0.9.0
2
+
3
+ * Initial gem release
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2014 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.
@@ -0,0 +1 @@
1
+ TODO
@@ -0,0 +1,6 @@
1
+ require_relative 'support/array'
2
+ require_relative 'support/dir'
3
+ require_relative 'support/dup'
4
+ require_relative 'support/file'
5
+ require_relative 'support/hash'
6
+ require_relative 'support/string'
@@ -0,0 +1,9 @@
1
+ class Array
2
+ def self.ensure(object)
3
+ if object.respond_to?(:to_ary)
4
+ object.to_ary
5
+ else
6
+ [object]
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,32 @@
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
@@ -0,0 +1,23 @@
1
+ module Pakyow
2
+ module Utils
3
+ module Dup
4
+ UNCLONEABLE = [Symbol, Fixnum]
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
@@ -0,0 +1,5 @@
1
+ class File
2
+ def self.format(path)
3
+ File.extname(path).delete('.')
4
+ end
5
+ end
@@ -0,0 +1,47 @@
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
@@ -0,0 +1,32 @@
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
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pakyow-support
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.0
5
+ platform: ruby
6
+ authors:
7
+ - Bryan Powell
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.1'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.1'
27
+ description: Supporting code used throughout Pakyow libraries.
28
+ email: bryan@metabahn.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - pakyow-support/CHANGES
34
+ - pakyow-support/MIT-LICENSE
35
+ - pakyow-support/README
36
+ - pakyow-support/lib/pakyow-support.rb
37
+ - pakyow-support/lib/support/array.rb
38
+ - pakyow-support/lib/support/dir.rb
39
+ - pakyow-support/lib/support/dup.rb
40
+ - pakyow-support/lib/support/file.rb
41
+ - pakyow-support/lib/support/hash.rb
42
+ - pakyow-support/lib/support/string.rb
43
+ homepage: http://pakyow.com
44
+ licenses:
45
+ - MIT
46
+ metadata: {}
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - pakyow-support/lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: 2.0.0
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubyforge_project:
63
+ rubygems_version: 2.2.2
64
+ signing_key:
65
+ specification_version: 4
66
+ summary: Support code for Pakyow apps.
67
+ test_files: []
68
+ has_rdoc: