filigree 0.3.3 → 0.4.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.
@@ -1,7 +1,7 @@
1
- # Author: Chris Wailes <chris.wailes@gmail.com>
2
- # Project: Filigree
3
- # Date: 2013/05/04
4
- # Description: Additional features for all objects.
1
+ # Author: Chris Wailes <chris.wailes+filigree@gmail.com>
2
+ # Project: Filigree
3
+ # Date: 2013/05/04
4
+ # Description: Additional features for all objects.
5
5
 
6
6
  ############
7
7
  # Requires #
@@ -29,12 +29,15 @@ end
29
29
  # Classes and Modules #
30
30
  #######################
31
31
 
32
- # Object class extras.
33
- class Object
34
- # A copy and modification helper.
35
- #
36
- # @return [Object] A copy of the object with the block evaluated in the context of the copy.
37
- def clone_with(&block)
38
- self.clone.tap { |clone| clone.instance_exec(&block) }
32
+ module Filigree
33
+
34
+ # Object class extras.
35
+ refine Object do
36
+ # A copy and modification helper.
37
+ #
38
+ # @return [Object] A copy of the object with the block evaluated in the context of the copy.
39
+ def clone_with(&block)
40
+ self.clone.tap { |clone| clone.instance_exec(&block) }
41
+ end
39
42
  end
40
43
  end
@@ -1,7 +1,7 @@
1
- # Author: Chris Wailes <chris.wailes@gmail.com>
2
- # Project: Filigree
3
- # Date: 2014/1/20
4
- # Description: A helper for require.
1
+ # Author: Chris Wailes <chris.wailes+filigree@gmail.com>
2
+ # Project: Filigree
3
+ # Date: 2014/1/20
4
+ # Description: A helper for require.
5
5
 
6
6
  ############
7
7
  # Requires #
@@ -1,7 +1,7 @@
1
- # Author: Chris Wailes <chris.wailes@gmail.com>
2
- # Project: Filigree
3
- # Date: 2014/01/20
4
- # Description: Class extensions for the String class.
1
+ # Author: Chris Wailes <chris.wailes+filigree@gmail.com>
2
+ # Project: Filigree
3
+ # Date: 2014/01/20
4
+ # Description: Class extensions for the String class.
5
5
 
6
6
  ############
7
7
  # Requires #
@@ -15,38 +15,40 @@
15
15
  # Classes and Modules #
16
16
  #######################
17
17
 
18
- class String
19
- # Chop up the string into multiple lines so that no line is longer than
20
- # the specified number of characters.
21
- #
22
- # @param [Fixnum] indent Indentation to put before each line; it is
23
- # assumed that this indentation is already present for the first line
24
- # @param [Fixnum] max_length Maximum length per line
25
- def segment(indent, max_length = 80)
26
- lines = Array.new
18
+ module Filigree
19
+ refine String do
20
+ # Chop up the string into multiple lines so that no line is longer than
21
+ # the specified number of characters.
22
+ #
23
+ # @param [Fixnum] indent Indentation to put before each line; it is
24
+ # assumed that this indentation is already present for the first line
25
+ # @param [Fixnum] max_length Maximum length per line
26
+ def segment(indent, max_length = 80)
27
+ lines = Array.new
27
28
 
28
- words = self.split(/\s/)
29
- line = words.shift
29
+ words = self.split(/\s/)
30
+ line = words.shift
30
31
 
31
- line_length = indent + line.length
32
+ line_length = indent + line.length
32
33
 
33
- words.each do |word|
34
- new_length = line_length + 1 + word.length
34
+ words.each do |word|
35
+ new_length = line_length + 1 + word.length
35
36
 
36
- if new_length < max_length
37
- line += " #{word}"
38
- line_length = new_length
37
+ if new_length < max_length
38
+ line += " #{word}"
39
+ line_length = new_length
39
40
 
40
- else
41
- lines << line
41
+ else
42
+ lines << line
42
43
 
43
- line = word
44
- line_length = indent + word.length
44
+ line = word
45
+ line_length = indent + word.length
46
+ end
45
47
  end
46
- end
47
48
 
48
- lines << line unless line.empty?
49
+ lines << line unless line.empty?
49
50
 
50
- lines.join("\n" + (' ' * indent))
51
+ lines.join("\n" + (' ' * indent))
52
+ end
51
53
  end
52
54
  end
@@ -1,7 +1,7 @@
1
- # Author: Chris Wailes <chris.wailes@gmail.com>
2
- # Project: Filigree
3
- # Date: 2013/05/04
4
- # Description: Extensions to help with type checking.
1
+ # Author: Chris Wailes <chris.wailes+filigree@gmail.com>
2
+ # Project: Filigree
3
+ # Date: 2013/05/04
4
+ # Description: Extensions to help with type checking.
5
5
 
6
6
  ############
7
7
  # Requires #
@@ -27,7 +27,7 @@ require 'filigree/class_methods_module'
27
27
  # @raise [ArgumentError] An error is raise if the type checking fails.
28
28
  #
29
29
  # @return [Object] The object passed as parameter obj
30
- def check_type(obj, type, blame = nil, nillable = false, strict = false)
30
+ def check_type(obj, type, blame: nil, nillable: false, strict: false)
31
31
  type_ok = (obj.nil? && nillable) || (strict ? obj.instance_of?(type) : obj.is_a?(type))
32
32
 
33
33
  if type_ok
@@ -54,7 +54,7 @@ end
54
54
  # @raise [ArgumentError] An error is raise if the type checking fails
55
55
  #
56
56
  # @return [Object] The object passed in parameter array
57
- def check_array_type(array, type, blame = nil, nillable = false, strict = false)
57
+ def check_array_type(array, type, blame: nil, nillable: false, strict: false)
58
58
  array.each do |obj|
59
59
  type_ok = (obj.nil? && nillable) || (strict ? obj.instance_of?(type) : obj.is_a?(type))
60
60
 
@@ -125,7 +125,7 @@ module Filigree
125
125
  # @return [void]
126
126
  def define_typed_accessor(name, nillable, strict, type, checker)
127
127
  define_method "#{name}=" do |obj|
128
- self.instance_variable_set("@#{name}", checker.call(obj, type, name, nillable, strict))
128
+ self.instance_variable_set("@#{name}", checker.call(obj, type, blame: name, nillable: nillable, strict: strict))
129
129
  end
130
130
  end
131
131
  private :define_typed_accessor
@@ -138,12 +138,11 @@ module Filigree
138
138
  # @param [Boolean] strict To use strict checking or not
139
139
  #
140
140
  # @return [void]
141
- def typed_ivar(name, type, nillable = false, strict = false)
141
+ def typed_ivar(name, type, nillable: false, strict: false)
142
142
  typed_ivars << name
143
143
 
144
144
  define_typed_accessor(name, nillable, strict, *
145
- type.is_a?(Array) ? [type.first, method(:check_array_type)] : [type, method(:check_type)]
146
- )
145
+ type.is_a?(Array) ? [type.first, method(:check_array_type)] : [type, method(:check_type)])
147
146
 
148
147
  attr_reader name
149
148
  end
@@ -1,8 +1,8 @@
1
- # Author: Chris Wailes <chris.wailes@gmail.com>
1
+ # Author: Chris Wailes <chris.wailes+filigree@gmail.com>
2
2
  # Project: Filigree
3
3
  # Date: 2013/4/19
4
4
  # Description: This file specifies the version number of Filigree.
5
5
 
6
6
  module Filigree
7
- VERSION = '0.3.3'
7
+ VERSION = '0.4.0'
8
8
  end
@@ -1,4 +1,4 @@
1
- # Author: Chris Wailes <chris.wailes@gmail.com>
1
+ # Author: Chris Wailes <chris.wailes+filigree@gmail.com>
2
2
  # Project: Filigree
3
3
  # Date: 2014/02/11
4
4
  # Description: An implementation of the Visitor pattern.
@@ -154,7 +154,7 @@ module Filigree
154
154
  add_pattern (mp = OuterPattern.new(pattern, guard, block))
155
155
 
156
156
  if block
157
- @deferred.each { |pattern| pattern.block = block }
157
+ @deferred.each { |deferred_pattern| deferred_pattern.block = block }
158
158
  @deferred.clear
159
159
 
160
160
  else
@@ -248,18 +248,18 @@ module Filigree
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
+ mod = visitor.visit(node) || mod
252
252
  end
253
253
 
254
254
  mod
255
255
 
256
256
  when :postorder
257
- res = children.flatten.compact.inject(false) { |mod, child| child.visit(visitor, :postorder) || mod }
257
+ res = children.flatten.compact.inject(false) { |modified, child| child.visit(visitor, :postorder) || modified }
258
258
  (visitor.visit(self) != MatchError) || res
259
259
 
260
260
  when :downup
261
261
  res = (visitor.visit(self) != MatchError)
262
- res = children.flatten.compact.inject(false) { |mod, child| child.visit(visitor, :downup) || mod } || res
262
+ res = children.flatten.compact.inject(false) { |modified, child| child.visit(visitor, :downup) || modified } || res
263
263
  (visitor.visit(self) != MatchError) || res
264
264
  end
265
265
  end
@@ -1,4 +1,4 @@
1
- # Author: Chris Wailes <chris.wailes@gmail.com>
1
+ # Author: Chris Wailes <chris.wailes+filigree@gmail.com>
2
2
  # Project: Filigree
3
3
  # Date: 2013/04/19
4
4
  # Description: Test cases for the AbstractClass module.
@@ -1,7 +1,7 @@
1
- # Author: Chris Wailes <chris.wailes@gmail.com>
2
- # Project: Filigree
3
- # Date: 2013/05/15
4
- # Description: Test cases for the Application module.
1
+ # Author: Chris Wailes <chris.wailes+filigree@gmail.com>
2
+ # Project: Filigree
3
+ # Date: 2013/05/15
4
+ # Description: Test cases for the Application module.
5
5
 
6
6
  ############
7
7
  # Requires #
@@ -43,7 +43,7 @@ class ApplicationTester < Minitest::Test
43
43
  end
44
44
 
45
45
  def test_application
46
- assert_raises(NoMethodError) { Foo.finalize }
46
+ assert_raises(NoMethodError) { Foo.finalize }
47
47
  Bar.finalize
48
48
  end
49
49
 
@@ -1,4 +1,4 @@
1
- # Author: Chris Wailes <chris.wailes@gmail.com>
1
+ # Author: Chris Wailes <chris.wailes+filigree@gmail.com>
2
2
  # Project: Filigree
3
3
  # Date: 2013/05/04
4
4
  # Description: Test cases for Boolean extensions.
@@ -18,6 +18,9 @@ require 'filigree/boolean'
18
18
  #######################
19
19
 
20
20
  class BooleanTester < Minitest::Test
21
+
22
+ using Filigree
23
+
21
24
  def setup
22
25
 
23
26
  end
@@ -1,7 +1,7 @@
1
- # Author: Chris Wailes <chris.wailes@gmail.com>
2
- # Project: Filigree
3
- # Date: 2013/05/04
4
- # Description: Test cases for Class extensions.
1
+ # Author: Chris Wailes <chris.wailes+filigree@gmail.com>
2
+ # Project: Filigree
3
+ # Date: 2013/05/04
4
+ # Description: Test cases for Class extensions.
5
5
 
6
6
  ############
7
7
  # Requires #
@@ -18,6 +18,9 @@ require 'filigree/class'
18
18
  #######################
19
19
 
20
20
  class ClassTester < Minitest::Test
21
+
22
+ using Filigree
23
+
21
24
  module Foo; end
22
25
 
23
26
  class Bar
@@ -36,10 +39,11 @@ class ClassTester < Minitest::Test
36
39
  assert Bar.includes_module?(Foo)
37
40
 
38
41
  assert_equal 'ClassTester::Bar::Baf', Bar::Baf.name
39
- assert_equal 'Baf', Bar::Baf.short_name
42
+ assert_equal 'Baf', Bar::Baf.short_name
40
43
 
41
44
  assert Baz.subclass_of?(Bar)
42
- assert !Baz.subclass_of?(Fixnum)
45
+ assert !Baz.subclass_of?(Integer)
46
+
43
47
  assert_raises(TypeError) { Baz.subclass_of?(1) }
44
48
  end
45
49
  end
@@ -1,4 +1,4 @@
1
- # Author: Chris Wailes <chris.wailes@gmail.com>
1
+ # Author: Chris Wailes <chris.wailes+filigree@gmail.com>
2
2
  # Project: Filigree
3
3
  # Date: 2013/05/15
4
4
  # Description: Test cases the InnerClassModule module.
@@ -1,7 +1,7 @@
1
- # Author: Chris Wailes <chris.wailes@gmail.com>
2
- # Project: Filigree
3
- # Date: 2013/05/17
4
- # Description: Test cases the Commands module.
1
+ # Author: Chris Wailes <chris.wailes+filigree@gmail.com>
2
+ # Project: Filigree
3
+ # Date: 2013/05/17
4
+ # Description: Test cases the Commands module.
5
5
 
6
6
  ############
7
7
  # Requires #
@@ -1,4 +1,4 @@
1
- # Author: Chris Wailes <chris.wailes@gmail.com>
1
+ # Author: Chris Wailes <chris.wailes+filigree@gmail.com>
2
2
  # Project: Filigree
3
3
  # Date: 2013/05/15
4
4
  # Description: Test cases the Configuration module.
@@ -39,8 +39,8 @@ class ConfigurationTester < Minitest::Test
39
39
  end
40
40
 
41
41
  help 'This does daf'
42
- option 'daf', 'd' do |*syms|
43
- syms.map { |syms| syms.to_sym }
42
+ option 'daf', 'd' do |*strings|
43
+ strings.map { |str| str.to_sym }
44
44
  end
45
45
 
46
46
  bool_option :bool
@@ -1,4 +1,4 @@
1
- # Author: Chris Wailes <chris.wailes@gmail.com>
1
+ # Author: Chris Wailes <chris.wailes+filigree@gmail.com>
2
2
  # Project: Filigree
3
3
  # Date: 2013/05/04
4
4
  # Description: Test cases for the match method.
@@ -19,7 +19,7 @@ require 'filigree/match'
19
19
 
20
20
  class MatchTester < Minitest::Test
21
21
 
22
- include Filigree
22
+ using Filigree
23
23
 
24
24
  ####################
25
25
  # Internal Classes #
@@ -99,33 +99,33 @@ class MatchTester < Minitest::Test
99
99
 
100
100
  def match_tester_class_pattern(o)
101
101
  match o do
102
- with(Fixnum.as a) { [:Fixnum, a] }
103
- with(Float.as a) { [:Float, a] }
104
- with(String.as a) { [:String, a] }
102
+ with(Integer.as a) { [:Integer, a] }
103
+ with(Float.as a) { [:Float, a] }
104
+ with(String.as a) { [:String, a] }
105
105
  end
106
106
  end
107
107
 
108
108
  def match_tester_literal(o)
109
109
  match o do
110
- with(Literal(Fixnum)) { :Fixnum }
111
- with(Literal(Float)) { :Float }
112
- with(Literal(/a/)) { :Regexp }
110
+ with(Literal(Integer)) { :Integer }
111
+ with(Literal(Float)) { :Float }
112
+ with(Literal(/a/)) { :Regexp }
113
113
  end
114
114
  end
115
115
 
116
116
  def match_tester_squiggle_bind(o)
117
117
  match o do
118
- with(Fixnum.as(~:a)) { [:Fixnum, a] }
119
- with(Float.as(~:a)) { [:Float, a] }
120
- with(String.as(~:a)) { [:String, a] }
118
+ with(Integer.as(~:a)) { [:Integer, a] }
119
+ with(Float.as(~:a)) { [:Float, a] }
120
+ with(String.as(~:a)) { [:String, a] }
121
121
  end
122
122
  end
123
123
 
124
124
  def match_tester_manual_bind(o)
125
125
  match o do
126
- with(Fixnum.as(Bind(:a))) { [:Fixnum, a] }
127
- with(Float.as(Bind(:a))) { [:Float, a] }
128
- with(String.as(Bind(:a))) { [:String, a] }
126
+ with(Integer.as(Bind(:a))) { [:Integer, a] }
127
+ with(Float.as(Bind(:a))) { [:Float, a] }
128
+ with(String.as(Bind(:a))) { [:String, a] }
129
129
  end
130
130
  end
131
131
 
@@ -154,7 +154,7 @@ class MatchTester < Minitest::Test
154
154
  end
155
155
 
156
156
  def match_tester_tuple(*touple)
157
- match *touple do
157
+ match(*touple) do
158
158
  with(1, 2) { :FOO }
159
159
  with(3, 4) { :BAR }
160
160
  with(5) { :BAF }
@@ -162,7 +162,7 @@ class MatchTester < Minitest::Test
162
162
  end
163
163
 
164
164
  def match_tester_tuple_wildcard(*touple)
165
- match *touple do
165
+ match(*touple) do
166
166
  with(1)
167
167
  with(2, 3) { :DEF }
168
168
  with(4, _) { :PART_WILD }
@@ -195,7 +195,7 @@ class MatchTester < Minitest::Test
195
195
  end
196
196
 
197
197
  def test_class_pattern
198
- assert_equal [:Fixnum, 42], match_tester_class_pattern(42)
198
+ assert_equal [:Integer, 42], match_tester_class_pattern(42)
199
199
  assert_equal [:Float, 42.0], match_tester_class_pattern(42.0)
200
200
  assert_equal [:String, 'foo'], match_tester_class_pattern('foo')
201
201
  end
@@ -236,19 +236,19 @@ class MatchTester < Minitest::Test
236
236
  end
237
237
 
238
238
  def test_literals
239
- assert_equal :Fixnum, match_tester_literal(Fixnum)
240
- assert_equal :Float, match_tester_literal(Float)
241
- assert_equal :Regexp, match_tester_literal(/a/)
239
+ assert_equal :Integer, match_tester_literal(Integer)
240
+ assert_equal :Float, match_tester_literal(Float)
241
+ assert_equal :Regexp, match_tester_literal(/a/)
242
242
  end
243
243
 
244
244
  def test_squiggle_bind
245
- assert_equal [:Fixnum, 42], match_tester_squiggle_bind(42)
245
+ assert_equal [:Integer, 42], match_tester_squiggle_bind(42)
246
246
  assert_equal [:Float, 42.0], match_tester_squiggle_bind(42.0)
247
247
  assert_equal [:String, 'foo'], match_tester_squiggle_bind('foo')
248
248
  end
249
249
 
250
250
  def test_manual_bind
251
- assert_equal [:Fixnum, 42], match_tester_manual_bind(42)
251
+ assert_equal [:Integer, 42], match_tester_manual_bind(42)
252
252
  assert_equal [:Float, 42.0], match_tester_manual_bind(42.0)
253
253
  assert_equal [:String, 'foo'], match_tester_manual_bind('foo')
254
254
  end