filigree 0.4.0 → 0.4.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: 7c7696d87311fb00c3506b41c1f8b50e944bb63b
4
- data.tar.gz: eb00162a46ccfbb5742e56498233f44e36b5d760
3
+ metadata.gz: b3c0573e398b2736c8f1e314ba3feb5aa21871c2
4
+ data.tar.gz: bbf5700aea71b6176e4b715f5667d732d30c454f
5
5
  SHA512:
6
- metadata.gz: 783be7b5c305016fe61287d6c41c7f49f7e15b380cf199cfcf0633ef5e2b4cd073cae6608879655d65d134b69554bf3d9c24195fccc908d6b8dd4a14c1425e34
7
- data.tar.gz: 98e5f988abc878f3f6da8e48faf8e29b547488a69f76bd3124d6541d0f321a87e7490c9a2f275068ca07dc91d35178cf090f91699ab4ab2ebcc5bc1f81f8b604
6
+ metadata.gz: 6517ac40aa42375670719f675c356b9cb25d6ba494ee44a30dffa3f44307a875d19139ae27350f42851f6a540dbab415adc887d13d3318987313c178344bdace
7
+ data.tar.gz: e15b6c5359816097a848e5a8bcf66a2ae83e98d6d421c8d79567e215427355d5ddcc02e08b2b4250ba9e5c3d4e0f656f4fb81d9770e8f863bb27049600a7ef39
data/README.md CHANGED
@@ -164,7 +164,11 @@ Filigree's implementation of the visitor pattern is built on the pattern matchin
164
164
  ```Ruby
165
165
  class Binary < Struct.new(:x, :y)
166
166
  extend Filigree::Destructurable
167
- include Filigree::Visitor
167
+ include Filigree::Visitable
168
+
169
+ def children
170
+ [x, y]
171
+ end
168
172
 
169
173
  def destructure(_)
170
174
  [x, y]
data/Rakefile CHANGED
@@ -76,16 +76,6 @@ request_file('reek/rake/task', 'Reek is not installed.') do
76
76
  end
77
77
  end
78
78
 
79
- ##################
80
- # Rubygems Tasks #
81
- ##################
82
-
83
- request_file('rubygems/tasks', 'Rubygems-tasks is not installed.') do
84
- Gem::Tasks.new do |t|
85
- t.console.command = 'pry'
86
- end
87
- end
88
-
89
79
  ########
90
80
  # YARD #
91
81
  ########
@@ -30,6 +30,8 @@ end
30
30
 
31
31
  module Filigree
32
32
  module Commands
33
+ using Filigree
34
+
33
35
  include ClassMethodsModule
34
36
 
35
37
  ####################
@@ -38,14 +40,23 @@ module Filigree
38
40
 
39
41
  # This will find the appropriate command and execute it.
40
42
  #
41
- # @param [String] line String containing the command to be processed and its arguments
43
+ # @param [String, Array<String>] overloaded String containing the command to be processed and its arguments
42
44
  #
43
45
  # @return [Object] Result of invoking the command's block
44
- def call(line)
45
- namespace, rest = self.class.get_namespace(line.split)
46
+ def call(overloaded)
47
+ split_line =
48
+ if overloaded.is_a?(String)
49
+ overloaded.split
50
+ elsif overloaded.is_a?(Array)
51
+ overloaded
52
+ else
53
+ raise TypeError, "Expected a String or Array of Strings."
54
+ end
55
+
56
+ namespace, rest = self.class.get_namespace(split_line)
46
57
 
47
58
  if namespace == self.class.commands
48
- raise CommandNotFoundError, line
59
+ raise CommandNotFoundError, split_line.join(' ')
49
60
  end
50
61
 
51
62
  command = namespace[:nil]
@@ -63,7 +74,9 @@ module Filigree
63
74
  if command.action.arity < 0 or command.action.arity == rest.length
64
75
  self.instance_exec(*rest, &action)
65
76
  else
66
- raise ArgumentError, "Wrong number of arguments for command: #{command.name}."
77
+ raise ArgumentError,
78
+ "Wrong number of arguments for command: #{command.name}. " +
79
+ "Expected #{command.action.arity} but got #{rest.length}."
67
80
  end
68
81
  end
69
82
 
@@ -209,7 +222,8 @@ module Filigree
209
222
  #################
210
223
 
211
224
  # The POD representing a command.
212
- Command = Struct.new(:name, :help, :param_help, :config, :action)
225
+ class Command < Struct.new(:name, :help, :param_help, :config, :action)
226
+ end
213
227
 
214
228
  ########################
215
229
  # Pre-defined Commands #
@@ -243,6 +257,8 @@ module Filigree
243
257
  puts Filigree::Configuration::Option.to_s(options, max_length + 4)
244
258
  end
245
259
 
260
+ puts
261
+ puts "\t#{comm.help}"
246
262
  puts
247
263
 
248
264
  if !comm.param_help.empty?
@@ -253,7 +269,7 @@ module Filigree
253
269
 
254
270
  segment_indent = max_param_len + 8
255
271
  comm.param_help.each do |name, help|
256
- printf " %-#{max_param_len}s - %s\n", name, help.segment(segment_indent)
272
+ printf "\t%-#{max_param_len}s - %s\n", name, help.segment(segment_indent)
257
273
  end
258
274
  end
259
275
  end
@@ -13,6 +13,12 @@
13
13
  require 'filigree/class_methods_module'
14
14
  require 'filigree/string'
15
15
 
16
+ #########
17
+ # Notes #
18
+ #########
19
+
20
+ # TODO: Add support for configuration destructors
21
+
16
22
  #######################
17
23
  # Classes and Modules #
18
24
  #######################
@@ -92,7 +98,7 @@ module Filigree
92
98
 
93
99
  case overloaded
94
100
  when Array
95
- handle_array_options(overloaded, set_opts)
101
+ handle_array_options(overloaded.clone, set_opts)
96
102
 
97
103
  when String, IO
98
104
  handle_serialized_options(overloaded, set_opts)
@@ -109,6 +115,13 @@ module Filigree
109
115
  self.class.required_options.each do |option|
110
116
  raise ArgumentError, "Option #{option} not set." if self.send(option).nil?
111
117
  end
118
+
119
+ # Initialize the auto options
120
+ self.class.auto_blocks.each do |name, block|
121
+ result = self.instance_exec(&block)
122
+
123
+ self.define_singleton_method(name) { result }
124
+ end
112
125
  end
113
126
 
114
127
  # Find the appropriate option object given a string.
@@ -127,6 +140,8 @@ module Filigree
127
140
 
128
141
  # Configure the object from an array of strings.
129
142
  #
143
+ # TODO: Improve the way arguments are pulled out of the ARGV array.
144
+ #
130
145
  # @param [Array<String>] argv String options
131
146
  # @param [Array<String>] set_opts List of names of options already added
132
147
  #
@@ -185,6 +200,8 @@ module Filigree
185
200
  #################
186
201
 
187
202
  module ClassMethods
203
+ # @return [Hash<Symbol, Block>] Hash of names to blocks used for auto configuration
204
+ attr_reader :auto_blocks
188
205
  # @return [Hash<String, Option>] Hash of options with long names used as keys
189
206
  attr_reader :options_long
190
207
  # @return [Hash<String, Option>] hash of options with short name used as keys
@@ -209,7 +226,7 @@ module Filigree
209
226
  #
210
227
  # @return [void]
211
228
  def auto(name, &block)
212
- define_method(name, &block)
229
+ @auto_blocks[name.to_sym] = block
213
230
  end
214
231
 
215
232
  # Define a boolean option. The variable will be set to true if
@@ -248,6 +265,7 @@ module Filigree
248
265
  #
249
266
  # @return [void]
250
267
  def install_icvars
268
+ @auto_blocks = Hash.new
251
269
  @help_string = ''
252
270
  @next_default = nil
253
271
  @next_required = false
@@ -266,8 +284,7 @@ module Filigree
266
284
  #
267
285
  # @return [void]
268
286
  def option(long, short = nil, conversions: nil, &block)
269
-
270
- long = long.to_s
287
+ long = long.to_s.gsub('-', '_')
271
288
  short = short.to_s if short
272
289
 
273
290
  add_option Option.new(long, short, @help_string, @next_default,
@@ -337,6 +354,8 @@ module Filigree
337
354
  # This class represents an option that can appear in the
338
355
  # configuration.
339
356
  class Option < Struct.new(:long, :short, :help, :default, :handler)
357
+ using Filigree
358
+
340
359
  # Returns the number of arguments that this option takes.
341
360
  #
342
361
  # @return [Fixnum] Number of arguments the option takes
@@ -350,7 +369,7 @@ module Filigree
350
369
  # Print the option information out as a string.
351
370
  #
352
371
  # Layout:
353
- # | ||--`long`,|| ||-`short`|| ~ |
372
+ # | ||--`long`,|| ||-`short`|| |
354
373
  # |_______||_________||_||________||___|
355
374
  # indent max_l+3 1 max_s+1 3
356
375
  #
@@ -364,9 +383,9 @@ module Filigree
364
383
  segmented_help = self.help.segment(segment_indent)
365
384
 
366
385
  if self.short
367
- sprintf "#{' ' * indent}%-#{max_long + 3}s %-#{max_short + 1}s ~ %s", "--#{self.long},", '-' + self.short, segmented_help
386
+ sprintf "#{' ' * indent}%-#{max_long + 3}s %-#{max_short + 1}s %s", "--#{self.long},", '-' + self.short, segmented_help
368
387
  else
369
- sprintf "#{' ' * indent}%-#{max_long + max_short + 5}s ~ %s", '--' + self.long, segmented_help
388
+ sprintf "#{' ' * indent}%-#{max_long + max_short + 5}s %s", '--' + self.long, segmented_help
370
389
  end
371
390
  end
372
391
 
@@ -396,7 +415,7 @@ module Filigree
396
415
 
397
416
  # The default help option. This can be added to your class via
398
417
  # add_option.
399
- HELP_OPTION = Option.new('help', 'h', 'Prints this help message.', nil, Proc.new do
418
+ HELP_OPTION = Option.new('help', 'h', 'Prints this help message', nil, Proc.new do
400
419
  puts "Usage: #{self.class.usage}"
401
420
  puts
402
421
  puts 'Options:'
@@ -22,9 +22,9 @@ require 'filigree/class'
22
22
  # An error that indicates that no pattern matched a given object.
23
23
  class MatchError < RuntimeError; end
24
24
 
25
- ###########
26
- # Methods #
27
- ###########
25
+ #######################
26
+ # Classes and Modules #
27
+ #######################
28
28
 
29
29
  # This is an implementation of pattern matching. The objects passed to match
30
30
  # are tested against the patterns defined inside the match block. The return
@@ -162,10 +162,6 @@ def match(*objects, &block)
162
162
  me.find_match(objects)
163
163
  end
164
164
 
165
- #######################
166
- # Classes and Modules #
167
- #######################
168
-
169
165
  module Filigree
170
166
 
171
167
  using Filigree
@@ -4,5 +4,5 @@
4
4
  # Description: This file specifies the version number of Filigree.
5
5
 
6
6
  module Filigree
7
- VERSION = '0.4.0'
7
+ VERSION = '0.4.1'
8
8
  end
@@ -241,17 +241,17 @@ module Filigree
241
241
  children.flatten.compact.inject(false) { |mod, child| child.visit(visitor, :preorder) || mod } || res
242
242
 
243
243
  when :inorder
244
- mod = false
244
+ lmod = false
245
245
  nodes = [self]
246
246
 
247
247
  # Not all Ruby implementations support modifying arrays while
248
248
  # you are iterating over them.
249
249
  while node = nodes.shift
250
250
  nodes += node.children.flatten.compact
251
- mod = visitor.visit(node) || mod
251
+ lmod = visitor.visit(node) || lmod
252
252
  end
253
253
 
254
- mod
254
+ lmod
255
255
 
256
256
  when :postorder
257
257
  res = children.flatten.compact.inject(false) { |modified, child| child.visit(visitor, :postorder) || modified }
@@ -153,16 +153,16 @@ class MatchTester < Minitest::Test
153
153
  end
154
154
  end
155
155
 
156
- def match_tester_tuple(*touple)
157
- match(*touple) do
156
+ def match_tester_tuple(*tuple)
157
+ match(*tuple)do
158
158
  with(1, 2) { :FOO }
159
159
  with(3, 4) { :BAR }
160
160
  with(5) { :BAF }
161
161
  end
162
162
  end
163
163
 
164
- def match_tester_tuple_wildcard(*touple)
165
- match(*touple) do
164
+ def match_tester_tuple_wildcard(*tuple)
165
+ match(*tuple)do
166
166
  with(1)
167
167
  with(2, 3) { :DEF }
168
168
  with(4, _) { :PART_WILD }
@@ -29,9 +29,6 @@ Hello, I am a test string.
29
29
  code can be tested.
30
30
  eos
31
31
 
32
- def setup
33
- end
34
-
35
32
  def test_segmentation
36
33
  assert_equal SEGMENTED.chomp, ORIGINAL.segment(2, 30)
37
34
  end
metadata CHANGED
@@ -1,167 +1,139 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: filigree
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Wailes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-15 00:00:00.000000000 Z
11
+ date: 2018-01-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: flay
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: flog
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: minitest
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: pry
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
66
+ - - "~>"
81
67
  - !ruby/object:Gem::Version
82
68
  version: '0'
83
69
  - !ruby/object:Gem::Dependency
84
70
  name: rake
85
71
  requirement: !ruby/object:Gem::Requirement
86
72
  requirements:
87
- - - ">="
73
+ - - "~>"
88
74
  - !ruby/object:Gem::Version
89
75
  version: '0'
90
76
  type: :development
91
77
  prerelease: false
92
78
  version_requirements: !ruby/object:Gem::Requirement
93
79
  requirements:
94
- - - ">="
80
+ - - "~>"
95
81
  - !ruby/object:Gem::Version
96
82
  version: '0'
97
83
  - !ruby/object:Gem::Dependency
98
84
  name: rake-notes
99
85
  requirement: !ruby/object:Gem::Requirement
100
86
  requirements:
101
- - - ">="
87
+ - - "~>"
102
88
  - !ruby/object:Gem::Version
103
89
  version: '0'
104
90
  type: :development
105
91
  prerelease: false
106
92
  version_requirements: !ruby/object:Gem::Requirement
107
93
  requirements:
108
- - - ">="
94
+ - - "~>"
109
95
  - !ruby/object:Gem::Version
110
96
  version: '0'
111
97
  - !ruby/object:Gem::Dependency
112
98
  name: reek
113
99
  requirement: !ruby/object:Gem::Requirement
114
100
  requirements:
115
- - - ">="
116
- - !ruby/object:Gem::Version
117
- version: '0'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - ">="
123
- - !ruby/object:Gem::Version
124
- version: '0'
125
- - !ruby/object:Gem::Dependency
126
- name: rubygems-tasks
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - ">="
101
+ - - "~>"
130
102
  - !ruby/object:Gem::Version
131
103
  version: '0'
132
104
  type: :development
133
105
  prerelease: false
134
106
  version_requirements: !ruby/object:Gem::Requirement
135
107
  requirements:
136
- - - ">="
108
+ - - "~>"
137
109
  - !ruby/object:Gem::Version
138
110
  version: '0'
139
111
  - !ruby/object:Gem::Dependency
140
112
  name: simplecov
141
113
  requirement: !ruby/object:Gem::Requirement
142
114
  requirements:
143
- - - ">="
115
+ - - "~>"
144
116
  - !ruby/object:Gem::Version
145
117
  version: '0'
146
118
  type: :development
147
119
  prerelease: false
148
120
  version_requirements: !ruby/object:Gem::Requirement
149
121
  requirements:
150
- - - ">="
122
+ - - "~>"
151
123
  - !ruby/object:Gem::Version
152
124
  version: '0'
153
125
  - !ruby/object:Gem::Dependency
154
126
  name: yard
155
127
  requirement: !ruby/object:Gem::Requirement
156
128
  requirements:
157
- - - ">="
129
+ - - "~>"
158
130
  - !ruby/object:Gem::Version
159
131
  version: 0.9.9
160
132
  type: :development
161
133
  prerelease: false
162
134
  version_requirements: !ruby/object:Gem::Requirement
163
135
  requirements:
164
- - - ">="
136
+ - - "~>"
165
137
  - !ruby/object:Gem::Version
166
138
  version: 0.9.9
167
139
  description: Filigree provides new classes and extensions to core library classes
@@ -205,7 +177,7 @@ files:
205
177
  - test/ts_filigree.rb
206
178
  homepage: https://github.com/chriswailes/filigree
207
179
  licenses:
208
- - University of Illinois/NCSA Open Source License
180
+ - NCSA
209
181
  metadata: {}
210
182
  post_install_message:
211
183
  rdoc_options: []
@@ -228,16 +200,16 @@ signing_key:
228
200
  specification_version: 4
229
201
  summary: Extra functionality for Ruby.
230
202
  test_files:
231
- - test/tc_boolean.rb
232
- - test/tc_object.rb
233
- - test/tc_types.rb
234
- - test/tc_configuration.rb
235
203
  - test/tc_commands.rb
204
+ - test/tc_types.rb
205
+ - test/tc_class.rb
236
206
  - test/tc_string.rb
207
+ - test/tc_application.rb
208
+ - test/tc_match.rb
237
209
  - test/tc_abstract_class.rb
238
- - test/tc_visitor.rb
210
+ - test/tc_object.rb
239
211
  - test/tc_class_methods_module.rb
240
- - test/tc_match.rb
241
- - test/tc_class.rb
242
- - test/tc_application.rb
212
+ - test/tc_configuration.rb
213
+ - test/tc_boolean.rb
214
+ - test/tc_visitor.rb
243
215
  - test/ts_filigree.rb