pakyow-support 0.10.0 → 0.10.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 18fe4035f112887d12a4721b40383f7a24c50065
4
- data.tar.gz: b3a5807b4bdf5ab10cf170c09536bfdab3e5405d
3
+ metadata.gz: 471e44351809ba270be27997124aedd4cf8337c4
4
+ data.tar.gz: 2b95d3a6ec45e1078945cd69d716233e0d607843
5
5
  SHA512:
6
- metadata.gz: 569dcad220acd75c60c28bedee9f91990d8f565505c18567d300ab844a6c0785cc57f1472ff3eb7ee1592a5e153ac87b4906c5347c5be9b16922cd2baec7cb2e
7
- data.tar.gz: e8e6207ed333345df34d9c1dac7e691f13719a6acfde185b77370aabc7308faced460094579c141d27d9dcc8b4e2e84aabef7b4593cc30ca22ef7eff12c302e7
6
+ metadata.gz: 413d3fd2d02a95c69e239aa8215dd098f3b985523565e4338bf4c58903d9995c0c09678fa6c4dd68a3b3c8f7e87de1316c63cfd94627644b5746b2c8b4831081
7
+ data.tar.gz: 07fb296faec52bbf6e026a2f9ae40084a4b2baf0f5856f8ac3861d2ea5b2d449bf625631a202ce5c6d22cf005f66085734675304b624bb6bd39065b1c96b07b7
@@ -0,0 +1,16 @@
1
+ # 0.10.1 / 2015-10-19
2
+
3
+ * Fixes require path in gemspec
4
+
5
+ # 0.10.0 / 2015-10-19
6
+
7
+ * Adds helper method for capitalizing a string
8
+ * Ported all tests to rspec
9
+
10
+ # 0.9.1 / 2014-12-06
11
+
12
+ * No changes -- bumped version to be consistent
13
+
14
+ # 0.9.0 / 2014-11-09
15
+
16
+ * Initial gem release
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013-2015 Bryan Powell
1
+ Copyright (c) 2014-2015 Bryan Powell
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -1,22 +1,22 @@
1
- # pakyow-rake
1
+ # pakyow-support
2
2
 
3
- Rake tasks for Pakyow projects.
3
+ Supporting code and Ruby core extensions for Pakyow.
4
4
 
5
5
  # Download
6
6
 
7
- The latest version of Pakyow Rake can be installed with RubyGems:
7
+ The latest version of Pakyow Support can be installed with RubyGems:
8
8
 
9
9
  ```
10
- gem install pakyow-rake
10
+ gem install pakyow-support
11
11
  ```
12
12
 
13
13
  Source code can be downloaded as part of the Pakyow project on Github:
14
14
 
15
- - https://github.com/pakyow/pakyow/tree/master/pakyow-rake
15
+ - https://github.com/pakyow/pakyow/tree/master/pakyow-support
16
16
 
17
17
  # License
18
18
 
19
- Pakyow Rake is released free and open-source under the [MIT
19
+ Pakyow Support is released free and open-source under the [MIT
20
20
  License](http://opensource.org/licenses/MIT).
21
21
 
22
22
  # Support
@@ -0,0 +1,8 @@
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'
7
+ require_relative 'support/aargv'
8
+ require_relative 'support/kernel'
@@ -0,0 +1,13 @@
1
+ class Aargv
2
+ def self.normalize(args, opts)
3
+ Hash[opts.map { |opt_name, opt_opts|
4
+ type, default = opt_opts
5
+
6
+ [opt_name, value_of_type(args, type) || default]
7
+ }.reject { |pair| pair[1].nil? }]
8
+ end
9
+
10
+ def self.value_of_type(values, type)
11
+ values.find { |value| value.is_a?(type) }
12
+ end
13
+ end
@@ -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,9 @@
1
+ module Kernel
2
+ def self.silence_warnings(&block)
3
+ warn_level = $VERBOSE
4
+ $VERBOSE = nil
5
+ result = block.call
6
+ $VERBOSE = warn_level
7
+ result
8
+ end
9
+ end
@@ -0,0 +1,36 @@
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pakyow-support
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.10.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryan Powell
@@ -30,13 +30,18 @@ executables: []
30
30
  extensions: []
31
31
  extra_rdoc_files: []
32
32
  files:
33
- - pakyow-rake/CHANGELOG.md
34
- - pakyow-rake/LICENSE
35
- - pakyow-rake/README.md
36
- - pakyow-rake/lib/pakyow-rake.rb
37
- - pakyow-rake/lib/tasks/app.rake
38
- - pakyow-rake/lib/tasks/bindings.rake
39
- - pakyow-rake/lib/tasks/routes.rake
33
+ - pakyow-support/CHANGELOG.md
34
+ - pakyow-support/LICENSE
35
+ - pakyow-support/README.md
36
+ - pakyow-support/lib/pakyow-support.rb
37
+ - pakyow-support/lib/support/aargv.rb
38
+ - pakyow-support/lib/support/array.rb
39
+ - pakyow-support/lib/support/dir.rb
40
+ - pakyow-support/lib/support/dup.rb
41
+ - pakyow-support/lib/support/file.rb
42
+ - pakyow-support/lib/support/hash.rb
43
+ - pakyow-support/lib/support/kernel.rb
44
+ - pakyow-support/lib/support/string.rb
40
45
  homepage: http://pakyow.org
41
46
  licenses:
42
47
  - MIT
@@ -44,7 +49,7 @@ metadata: {}
44
49
  post_install_message:
45
50
  rdoc_options: []
46
51
  require_paths:
47
- - pakyow-rake/lib
52
+ - pakyow-support/lib
48
53
  required_ruby_version: !ruby/object:Gem::Requirement
49
54
  requirements:
50
55
  - - ">="
@@ -1,11 +0,0 @@
1
- # 0.10.0 (to be released)
2
-
3
- * TODO
4
-
5
- # 0.9.1 / 2014-12-06
6
-
7
- * No changes -- bumped version to be consistent
8
-
9
- # 0.9.0 / 2014-11-09
10
-
11
- * Initial gem release
@@ -1,4 +0,0 @@
1
- libdir = File.dirname(__FILE__)
2
- $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
3
-
4
- Dir["#{libdir}/tasks/*.rake"].sort.each { |task| load task }
@@ -1,13 +0,0 @@
1
- namespace :pakyow do
2
- desc 'Prepare the app by configuring and loading code'
3
- task :prepare do
4
- require './app/setup'
5
- Pakyow::App.prepare(ENV['APP_ENV'] || ENV['RACK_ENV'])
6
- end
7
-
8
- desc 'Stage the app by preparing and loading routes / views'
9
- task :stage do
10
- require './app/setup'
11
- Pakyow::App.stage(ENV['APP_ENV'] || ENV['RACK_ENV'])
12
- end
13
- end
@@ -1,57 +0,0 @@
1
- namespace :pakyow do
2
- desc 'List bindings across all views, or a specific view path'
3
- task :bindings, [:view_path] => :stage do |t, args|
4
- BindingAnalyzer.analyze(args[:view_path])
5
- end
6
- end
7
-
8
- class BindingAnalyzer
9
- def self.analyze(view_path)
10
- bindings = []
11
-
12
- Pakyow::Config.presenter.view_stores.each_pair do |view_store, store_path|
13
- Pakyow.app.presenter.store(view_store).infos do |info, path|
14
- path = String.normalize_path(path) unless path == "/"
15
- next if view_path && path != String.normalize_path(view_path)
16
- next if bindings.select{|b| b[:path] == path}.length > 0
17
-
18
- view = Pakyow.app.presenter.store(view_store).view(path)
19
- bindings << { path: path, scopes: view.doc.scopes}
20
- end
21
- end
22
-
23
- bindings.each do |set|
24
- set[:path] = '/' if set[:path].empty?
25
- next if set[:scopes].empty?
26
-
27
- Pakyow.logger << "\n" + set[:path]
28
-
29
- log_bindings(set[:scopes])
30
- end
31
- end
32
-
33
- def self.log_bindings(bindings, nested = "")
34
- bindings.each do |binding|
35
- space = " "
36
-
37
- scope_str = space.dup
38
- scope_str << "#{nested} > " unless nested.empty?
39
- scope_str << binding[:scope].to_s
40
- Pakyow.logger << scope_str
41
-
42
- props = binding[:props]
43
- if props.count > 0
44
- binding[:props].each {|prop|
45
- Pakyow.logger << space + " #{prop[:prop]}"
46
- }
47
- else
48
- Pakyow.logger << space + " (no props)"
49
- end
50
-
51
-
52
- next_nested = binding[:scope]
53
- next_nested = "#{nested} > #{next_nested}" unless nested.empty?
54
- log_bindings(binding[:nested], next_nested)
55
- end
56
- end
57
- end
@@ -1,42 +0,0 @@
1
- namespace :pakyow do
2
- desc 'List all routes (method, path, group[name])'
3
- task :routes => [:stage] do
4
- Pakyow::Router.instance.sets.each do |set_data|
5
- set_name, set = set_data
6
-
7
- Pakyow.logger << "\n#{set_name} routes"
8
-
9
- all_routes = []
10
- set.routes.each {|route_data|
11
- method, routes = route_data
12
-
13
- routes.each {|route|
14
- group = nil
15
- set.lookup[:grouped].each_pair {|name,routes|
16
- if routes.values.include?(route)
17
- group = name
18
- break
19
- end
20
- }
21
-
22
- name = route[2]
23
- name = "#{group}[#{name}]" if group
24
-
25
- all_routes << {
26
- method: method,
27
- path: File.join('/', route[4]),
28
- name: name
29
- }
30
- }
31
- }
32
-
33
- all_routes.sort{|a,b| a[:path] <=> b[:path]}.each {|route|
34
- s = " #{route[:method].upcase}\t#{route[:path]}"
35
- s << ", #{route[:name]}" if route[:name]
36
- Pakyow.logger << s
37
- }
38
-
39
- Pakyow.logger << ''
40
- end
41
- end
42
- end