pa 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -0
- data/Gemfile.lock +2 -0
- data/lib/pa.rb +1 -4
- data/version.rb +1 -1
- metadata +2 -3
- data/lib/pa/core.rb +0 -106
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
data/lib/pa.rb
CHANGED
data/version.rb
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: pa
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.0.
|
5
|
+
version: 1.0.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Guten
|
@@ -98,7 +98,6 @@ files:
|
|
98
98
|
- Ragfile
|
99
99
|
- lib/pa.rb
|
100
100
|
- lib/pa/cmd.rb
|
101
|
-
- lib/pa/core.rb
|
102
101
|
- lib/pa/dir.rb
|
103
102
|
- lib/pa/path.rb
|
104
103
|
- lib/pa/state.rb
|
@@ -123,7 +122,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
123
122
|
requirements:
|
124
123
|
- - ">="
|
125
124
|
- !ruby/object:Gem::Version
|
126
|
-
hash:
|
125
|
+
hash: -3646462436078976361
|
127
126
|
segments:
|
128
127
|
- 0
|
129
128
|
version: "0"
|
data/lib/pa/core.rb
DELETED
@@ -1,106 +0,0 @@
|
|
1
|
-
class Array
|
2
|
-
|
3
|
-
=begin
|
4
|
-
# extend options are symbols and hash, symbol as a boolean option.
|
5
|
-
#
|
6
|
-
# :a #=> { a: true }
|
7
|
-
# :_a #=> { a: false}
|
8
|
-
#
|
9
|
-
# @example
|
10
|
-
# def foo(*args)
|
11
|
-
# paths, o = args.extract_extend_options
|
12
|
-
# end
|
13
|
-
#
|
14
|
-
# foo(1, :a, :_b, :c => 2)
|
15
|
-
# #=> paths is [1]
|
16
|
-
# #=> o is {a: true, b: false, c: 2}
|
17
|
-
#
|
18
|
-
# @param [Symbol, Hash] *defaults
|
19
|
-
# @return [Array<Object>, Hash] \[args, options]
|
20
|
-
def extract_extend_options *defaults
|
21
|
-
args, o = _parse_o(defaults)
|
22
|
-
args1, o1 = _parse_o(self)
|
23
|
-
[args+args1, o.merge(o1)]
|
24
|
-
end
|
25
|
-
|
26
|
-
# modify args IN PLACE.
|
27
|
-
# @ see extract_extend_options
|
28
|
-
#
|
29
|
-
# @example
|
30
|
-
# def foo(*args)
|
31
|
-
# options = args.extract_extend_options!
|
32
|
-
# end
|
33
|
-
#
|
34
|
-
# foo(1, :a, :_b, c: 2)
|
35
|
-
# #=> args is [1]
|
36
|
-
# #=> o is {a: true, b: false, c:2}
|
37
|
-
#
|
38
|
-
# @param [Symbol, Hash] *defaults
|
39
|
-
# @return [Hash] options
|
40
|
-
def extract_extend_options! *defaults
|
41
|
-
args, o = extract_extend_options *defaults
|
42
|
-
self.replace args
|
43
|
-
o
|
44
|
-
end
|
45
|
-
|
46
|
-
# @param [Array,Hash] args
|
47
|
-
def _parse_o args
|
48
|
-
args = args.dup
|
49
|
-
# name:1
|
50
|
-
o1 = Hash === args.last ? args.pop : {}
|
51
|
-
# :force :_force
|
52
|
-
rst = args.select{|v| Symbol===v}
|
53
|
-
args.delete_if{|v| Symbol===v}
|
54
|
-
o2={}
|
55
|
-
rst.each do |k|
|
56
|
-
v = true
|
57
|
-
if k=~/^_/
|
58
|
-
k = k[1..-1].to_sym
|
59
|
-
v = false
|
60
|
-
end
|
61
|
-
o2[k] = v
|
62
|
-
end
|
63
|
-
[args, o1.merge(o2)]
|
64
|
-
end
|
65
|
-
private :_parse_o
|
66
|
-
=end
|
67
|
-
|
68
|
-
# Extracts options from a set of arguments. Removes and returns the last
|
69
|
-
# element in the array if it's a hash, otherwise returns a blank hash.
|
70
|
-
# you can also pass a default option.
|
71
|
-
#
|
72
|
-
# @example
|
73
|
-
# def options(*args)
|
74
|
-
# o = args.extract_options!(:a=>1)
|
75
|
-
# end
|
76
|
-
#
|
77
|
-
# options(1, 2) # => {:a=>1}
|
78
|
-
# options(1, 2, :a => :b) # => {:a=>:b}
|
79
|
-
#
|
80
|
-
# @param [Hash] default default options
|
81
|
-
# @return [Hash]
|
82
|
-
def extract_options! default={}
|
83
|
-
if self.last.is_a?(Hash) && self.last.instance_of?(Hash)
|
84
|
-
self.pop.merge default
|
85
|
-
else
|
86
|
-
default
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
# extract options
|
91
|
-
# @see extract_options!
|
92
|
-
# @example
|
93
|
-
# def mkdir(*args)
|
94
|
-
# paths, o = args.extract_options
|
95
|
-
# end
|
96
|
-
#
|
97
|
-
# @return [Array<Array,Hash>]
|
98
|
-
def extract_options default={}
|
99
|
-
if self.last.is_a?(Hash) && self.last.instance_of?(Hash)
|
100
|
-
[self[0...-1], self[-1].merge(default)]
|
101
|
-
else
|
102
|
-
[self, default]
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
end
|