gorillib 0.1.11 → 0.4.0pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (143) hide show
  1. data/.gitignore +1 -0
  2. data/.rspec +1 -2
  3. data/.yardopts +9 -0
  4. data/{CHANGELOG.textile → CHANGELOG.md} +35 -9
  5. data/Gemfile +21 -14
  6. data/Guardfile +19 -0
  7. data/{LICENSE.textile → LICENSE.md} +43 -29
  8. data/README.md +47 -52
  9. data/Rakefile +31 -30
  10. data/TODO.md +32 -0
  11. data/VERSION +1 -1
  12. data/examples/builder/ironfan.rb +133 -0
  13. data/examples/model/simple.rb +17 -0
  14. data/gorillib.gemspec +106 -86
  15. data/lib/alt/kernel/call_stack.rb +56 -0
  16. data/lib/gorillib/array/wrap.rb +53 -0
  17. data/lib/gorillib/base.rb +3 -3
  18. data/lib/gorillib/builder/field.rb +5 -0
  19. data/lib/gorillib/builder.rb +260 -0
  20. data/lib/gorillib/collection/has_collection.rb +31 -0
  21. data/lib/gorillib/collection.rb +129 -0
  22. data/lib/gorillib/configurable.rb +28 -0
  23. data/lib/gorillib/datetime/{flat.rb → to_flat.rb} +0 -0
  24. data/lib/gorillib/exception/confidence.rb +17 -0
  25. data/lib/gorillib/exception/raisers.rb +78 -0
  26. data/lib/gorillib/hash/mash.rb +202 -0
  27. data/lib/gorillib/hashlike/slice.rb +53 -19
  28. data/lib/gorillib/hashlike.rb +5 -3
  29. data/lib/gorillib/io/system_helpers.rb +30 -0
  30. data/lib/gorillib/logger/log.rb +18 -0
  31. data/lib/gorillib/metaprogramming/concern.rb +124 -0
  32. data/lib/gorillib/model/active_model_conversion.rb +68 -0
  33. data/lib/gorillib/model/active_model_naming.rb +87 -0
  34. data/lib/gorillib/model/active_model_shim.rb +33 -0
  35. data/lib/gorillib/model/base.rb +341 -0
  36. data/lib/gorillib/model/defaults.rb +71 -0
  37. data/lib/gorillib/model/errors.rb +14 -0
  38. data/lib/gorillib/model/factories.rb +372 -0
  39. data/lib/gorillib/model/field.rb +146 -0
  40. data/lib/gorillib/model/named_schema.rb +53 -0
  41. data/lib/gorillib/{struct/hashlike_iteration.rb → model/overlay.rb} +0 -0
  42. data/lib/gorillib/model/record_schema.rb +9 -0
  43. data/lib/gorillib/model/serialization.rb +23 -0
  44. data/lib/gorillib/model/validate.rb +22 -0
  45. data/lib/gorillib/model.rb +23 -0
  46. data/lib/gorillib/pathname.rb +78 -0
  47. data/lib/gorillib/{serialization.rb → serialization/to_wire.rb} +0 -0
  48. data/lib/gorillib/some.rb +11 -9
  49. data/lib/gorillib/string/constantize.rb +21 -14
  50. data/lib/gorillib/string/inflections.rb +6 -76
  51. data/lib/gorillib/string/inflector.rb +192 -0
  52. data/lib/gorillib/string/simple_inflector.rb +267 -0
  53. data/lib/gorillib/type/extended.rb +52 -0
  54. data/lib/gorillib/utils/capture_output.rb +28 -0
  55. data/lib/gorillib/utils/console.rb +131 -0
  56. data/lib/gorillib/utils/nuke_constants.rb +9 -0
  57. data/lib/gorillib/utils/stub_module.rb +33 -0
  58. data/spec/examples/builder/ironfan_spec.rb +37 -0
  59. data/spec/extlib/hash_spec.rb +64 -0
  60. data/spec/extlib/mash_spec.rb +312 -0
  61. data/spec/{array → gorillib/array}/compact_blank_spec.rb +2 -2
  62. data/spec/{array → gorillib/array}/extract_options_spec.rb +2 -2
  63. data/spec/gorillib/builder_spec.rb +187 -0
  64. data/spec/gorillib/collection_spec.rb +20 -0
  65. data/spec/gorillib/configurable_spec.rb +62 -0
  66. data/spec/{datetime → gorillib/datetime}/parse_spec.rb +3 -3
  67. data/spec/{datetime/flat_spec.rb → gorillib/datetime/to_flat_spec.rb} +4 -4
  68. data/spec/{enumerable → gorillib/enumerable}/sum_spec.rb +5 -5
  69. data/spec/gorillib/exception/raisers_spec.rb +60 -0
  70. data/spec/{hash → gorillib/hash}/compact_spec.rb +2 -2
  71. data/spec/{hash → gorillib/hash}/deep_compact_spec.rb +3 -3
  72. data/spec/{hash → gorillib/hash}/deep_merge_spec.rb +2 -2
  73. data/spec/{hash → gorillib/hash}/keys_spec.rb +2 -2
  74. data/spec/{hash → gorillib/hash}/reverse_merge_spec.rb +2 -2
  75. data/spec/{hash → gorillib/hash}/slice_spec.rb +2 -2
  76. data/spec/{hash → gorillib/hash}/zip_spec.rb +2 -2
  77. data/spec/{hashlike → gorillib/hashlike}/behave_same_as_hash_spec.rb +6 -3
  78. data/spec/{hashlike → gorillib/hashlike}/deep_hash_spec.rb +2 -2
  79. data/spec/{hashlike → gorillib/hashlike}/hashlike_behavior_spec.rb +32 -30
  80. data/spec/{hashlike → gorillib/hashlike}/hashlike_via_accessors_spec.rb +3 -3
  81. data/spec/{hashlike_spec.rb → gorillib/hashlike_spec.rb} +3 -3
  82. data/spec/{logger → gorillib/logger}/log_spec.rb +2 -2
  83. data/spec/{metaprogramming → gorillib/metaprogramming}/aliasing_spec.rb +3 -3
  84. data/spec/{metaprogramming → gorillib/metaprogramming}/class_attribute_spec.rb +3 -3
  85. data/spec/{metaprogramming → gorillib/metaprogramming}/delegation_spec.rb +3 -3
  86. data/spec/{metaprogramming → gorillib/metaprogramming}/singleton_class_spec.rb +3 -3
  87. data/spec/gorillib/model/record/defaults_spec.rb +108 -0
  88. data/spec/gorillib/model/record/factories_spec.rb +321 -0
  89. data/spec/gorillib/model/record/overlay_spec.rb +46 -0
  90. data/spec/gorillib/model/serialization_spec.rb +48 -0
  91. data/spec/gorillib/model_spec.rb +281 -0
  92. data/spec/{numeric → gorillib/numeric}/clamp_spec.rb +2 -2
  93. data/spec/{object → gorillib/object}/blank_spec.rb +2 -2
  94. data/spec/{object → gorillib/object}/try_dup_spec.rb +2 -2
  95. data/spec/{object → gorillib/object}/try_spec.rb +3 -2
  96. data/spec/gorillib/pathname_spec.rb +114 -0
  97. data/spec/{string → gorillib/string}/constantize_spec.rb +2 -2
  98. data/spec/{string → gorillib/string}/human_spec.rb +2 -2
  99. data/spec/{string → gorillib/string}/inflections_spec.rb +4 -3
  100. data/spec/{string → gorillib/string}/inflector_test_cases.rb +0 -0
  101. data/spec/{string → gorillib/string}/truncate_spec.rb +4 -10
  102. data/spec/gorillib/type/extended_spec.rb +120 -0
  103. data/spec/gorillib/utils/capture_output_spec.rb +71 -0
  104. data/spec/spec_helper.rb +8 -11
  105. data/spec/support/gorillib_test_helpers.rb +66 -0
  106. data/spec/support/hashlike_fuzzing_helper.rb +31 -33
  107. data/spec/support/hashlike_helper.rb +3 -3
  108. data/spec/support/model_test_helpers.rb +81 -0
  109. data/spec/support/shared_examples/included_module.rb +20 -0
  110. metadata +177 -158
  111. data/lib/gorillib/array/average.rb +0 -13
  112. data/lib/gorillib/array/sorted_median.rb +0 -11
  113. data/lib/gorillib/array/sorted_percentile.rb +0 -11
  114. data/lib/gorillib/array/sorted_sample.rb +0 -12
  115. data/lib/gorillib/dsl_object.rb +0 -64
  116. data/lib/gorillib/hash/indifferent_access.rb +0 -207
  117. data/lib/gorillib/hash/tree_merge.rb +0 -4
  118. data/lib/gorillib/hashlike/tree_merge.rb +0 -49
  119. data/lib/gorillib/metaprogramming/cattr_accessor.rb +0 -79
  120. data/lib/gorillib/metaprogramming/mattr_accessor.rb +0 -61
  121. data/lib/gorillib/receiver/active_model_shim.rb +0 -32
  122. data/lib/gorillib/receiver/acts_as_hash.rb +0 -195
  123. data/lib/gorillib/receiver/acts_as_loadable.rb +0 -42
  124. data/lib/gorillib/receiver/locale/en.yml +0 -27
  125. data/lib/gorillib/receiver/tree_diff.rb +0 -74
  126. data/lib/gorillib/receiver/validations.rb +0 -30
  127. data/lib/gorillib/receiver.rb +0 -402
  128. data/lib/gorillib/receiver_model.rb +0 -21
  129. data/lib/gorillib/struct/acts_as_hash.rb +0 -108
  130. data/notes/fancy_hashes_and_receivers.textile +0 -120
  131. data/notes/hash_rdocs.textile +0 -97
  132. data/spec/array/average_spec.rb +0 -24
  133. data/spec/array/sorted_median_spec.rb +0 -18
  134. data/spec/array/sorted_percentile_spec.rb +0 -24
  135. data/spec/array/sorted_sample_spec.rb +0 -28
  136. data/spec/dsl_object_spec.rb +0 -99
  137. data/spec/hash/indifferent_access_spec.rb +0 -391
  138. data/spec/metaprogramming/cattr_accessor_spec.rb +0 -43
  139. data/spec/metaprogramming/mattr_accessor_spec.rb +0 -45
  140. data/spec/receiver/acts_as_hash_spec.rb +0 -295
  141. data/spec/receiver_spec.rb +0 -551
  142. data/spec/struct/acts_as_hash_fuzz_spec.rb +0 -71
  143. data/spec/struct/acts_as_hash_spec.rb +0 -422
@@ -1,120 +0,0 @@
1
-
2
- * gorillib/hashlike
3
- * gorillib/hashlike/slice
4
- * gorillib/hashlike/deep_dup
5
- * gorillib/hashlike/
6
- * gorillib/hashlike/hashlike_via_accessors
7
- * gorillib/struct/acts_as_hash
8
- * gorillib/struct/iterates_as_hash
9
-
10
-
11
-
12
- h4. acts_as_hash
13
-
14
- * []= associates key with value
15
- * [] retrieves value associated with given key
16
- * delete removes that key and its association
17
- * keys enumeration of all keys having associations.
18
-
19
-
20
- * check for compatibility/semantics of Enumerable
21
- * has_key? true if an association exists for the given key.
22
-
23
- h4. hashlike
24
-
25
- Want chokepoints:
26
-
27
- keys
28
- - each, each_pair
29
- - each_value
30
- - reject!
31
- - delete_if
32
- - reject
33
- - select!
34
- - keep_if
35
- - each_key
36
- - key
37
- - has_key?
38
- - values_at
39
- - length, size
40
- - empty?
41
-
42
-
43
- * each keys.each{|k| yield [k, self[k]] } ; self
44
-
45
- * has_key? keys.include?(k)
46
- * length keys.length
47
- * size alias for length
48
- * empty? keys.empty?
49
-
50
- * each_pair alias for each
51
- * each_key keys.each{|k| yield k }
52
- * each_value each{|k,v| yield v }
53
- * key keys.find{|k| self[k] == val }
54
- * values_at in_keys.each{|k| self[k] if has_key?(k) }
55
- * values [].tap{|arr| each{|k,v| arr << v } }
56
- * to_hash {}.tap{|hsh| each{|k,v| hsh[k] = v } }
57
-
58
- * has_value? keys.any?{|k| self[k] == val }
59
- * value? alias for has_value?
60
- * include? alias for has_key?
61
- * key? alias for has_key?
62
- * member? alias for has_key?
63
-
64
- * update other_hash.each{|k,v| self[k] = (block_given? && has_key?(k) ? yield(k,v,self[k]) : v) }
65
- * merge! update
66
- * merge dup.merge!
67
-
68
- * reject! chgd = false ; each{|k,v| if yield(k,v) then delete(k); chgd = true ; end } chgd ? self : nil
69
- * select! chgd = false ; each{|k,v| if !yield(k,v) then delete(k); chgd = true ; end } chgd ? self : nil
70
- * delete_if: reject! ; return self
71
- * keep_if: select! ; return self
72
- * reject: self.dup.delete_if
73
-
74
- * fetch [] if has_key? else default else yield else raise KeyError
75
- * clear each_key{|k| delete(k) }
76
-
77
- * invert to_hash.invert
78
-
79
-
80
-
81
- #all?, #any?, #chunk, #collect, #collect_concat, #count, #cycle, #detect,
82
- #drop, #drop_while, #each_cons, #each_entry, #each_slice,
83
- #each_with_index, #each_with_object, #entries, #find, #find_all,
84
- #find_index, #first, #flat_map, #grep, #group_by, #inject, #map, #max,
85
- #max_by, #min, #min_by, #minmax, #minmax_by, #none?, #one?, #partition,
86
- #reduce, #reverse_each, #slice_before, #sort, #sort_by, #take,
87
- #take_while, #zip
88
-
89
- As opposed to hash, does *not* define
90
-
91
- default, default=, default_proc, default_proc=,
92
- replace, rehash, compare_by_identity compare_by_identity?,
93
- shift, flatten,
94
-
95
- h4. Configliere::DeepHash -- a magic hash
96
-
97
- - only allows handles as keys (only things that can be turned into symbols are interesting)
98
- - indifferent access
99
- - deep access, via the dotted hash
100
-
101
- * FancyHash
102
-
103
- * *gorillib/hash/compact* compact, compact!, compact_blank, compact_blank!
104
- * *gorrilib/hash/deep_compact* deep_compact, deep_compact!
105
- * *gorrilib/hash/deep_merge* deep_merge, deep_merge!
106
- * *gorillib/hash/keys* stringify_keys, stringify_keys!, symbolize_keys, symbolize_keys!, assert_valid_keys
107
- * *gorillib/hash/reverse_merge* reverse_merge, reverse_merge!
108
- * *gorillib/hash/tree_merge* tree_merge, tree_merge!
109
- * *gorillib/hash/slice* slice, slice!, extract!
110
- * *gorillib/hash/zip* Hash.zip
111
-
112
- * Receiver
113
-
114
-
115
- ===========================================================================
116
- ===========================================================================
117
-
118
-
119
- ?> [ :store, :delete, :keys, :each, :each_key, :each_value, :has_key?, :include?, :key?, :member?, :has_value?, :value?, :fetch, :length, :empty?, :to_hash, :values, :values_at, :merge, :update, :key, :invert, :reject!, :select!, :delete_if, :keep_if, :reject, :clear, :assoc, :rassoc].each{|m| puts `ri 'Hash##{m}'` }
120
-
@@ -1,97 +0,0 @@
1
-
2
- # == Hashlike ==
3
- #
4
- # == ActsAsHash ==
5
- #
6
- # Uses accessors and instance variables to provide
7
- # * :[key] calls the getter <tt>send(key)</tt>
8
- # * :[key]= val calls the setter <tt>send("key=", val)</tt>
9
- # * :delete removes the instance variable, calls unset!
10
- # * :keys all instance variables
11
- #
12
- # == Hashlike::Slice ==
13
- # == Hashlike::Keys ==
14
- # == Hashlike::Compact ==
15
- # == Hashlike::DeepCompact ==
16
- # == Hashlike::DeepMerge ==
17
- # == Hashlike::TreeMerge ==
18
- # == Hashlike::ReverseMerge ==
19
- # == Hashlike::Zip ==
20
- # == Hashlike::DeepKeys ==
21
-
22
-
23
- # Hashlike#each
24
-
25
-
26
- # Hashlike#each_key
27
-
28
-
29
- # Hashlike#each_value
30
-
31
-
32
- # Hashlike#has_key?
33
-
34
-
35
- # Hashlike#include?
36
- # Hashlike#key?
37
- # Hashlike#member?
38
-
39
- # Hashlike#has_value?
40
- # Hashlike#value?
41
-
42
-
43
- # Hashlike#fetch
44
-
45
-
46
- # Hashlike#length
47
-
48
-
49
- # Hashlike#empty?
50
-
51
-
52
- # Hashlike#to_hash
53
-
54
-
55
- # Hashlike#values
56
-
57
-
58
- # Hashlike#values_at
59
-
60
-
61
- # Hashlike#key
62
-
63
-
64
- # Hashlike#invert
65
-
66
-
67
- # Hashlike#delete_if
68
-
69
-
70
- # Hashlike#reject!
71
-
72
-
73
- # Hashlike#reject
74
-
75
-
76
- # Hashlike#keep_if
77
-
78
-
79
- # Hashlike#select!
80
-
81
-
82
- # Hashlike#clear
83
-
84
-
85
- # Hashlike#assoc
86
-
87
-
88
- # Hashlike#rassoc
89
-
90
-
91
- # Hashlike#flatten
92
-
93
-
94
- # Hashlike#update
95
-
96
-
97
- # Hashlike#merge
@@ -1,24 +0,0 @@
1
- require File.expand_path('../spec_helper', File.dirname(__FILE__))
2
- require 'gorillib/array/average'
3
-
4
- describe Array do
5
- describe '#average' do
6
- context 'on non-float array element' do
7
- it 'raises error' do
8
- expect { [0.0, :b, 1.0].average }.should raise_error(ArgumentError)
9
- end
10
- end
11
-
12
- context 'with empty' do
13
- it 'returns nil' do
14
- [].average.should be_nil
15
- end
16
- end
17
-
18
- context 'given a numerical array' do
19
- it 'returns the average of the elements' do
20
- (1..10).to_a.average.should == 5.5
21
- end
22
- end
23
- end
24
- end
@@ -1,18 +0,0 @@
1
- require File.expand_path('../spec_helper', File.dirname(__FILE__))
2
- require 'gorillib/array/sorted_median'
3
-
4
- describe Array do
5
- describe '#sorted_median' do
6
- context 'with empty' do
7
- it 'returns nil' do
8
- [].sorted_median.should be_nil
9
- end
10
- end
11
-
12
- context 'given any array' do
13
- it 'returns the middle element of odd-sized arrays' do
14
- ("a".."y").to_a.sorted_median.should == "m"
15
- end
16
- end
17
- end
18
- end
@@ -1,24 +0,0 @@
1
- require File.expand_path('../spec_helper', File.dirname(__FILE__))
2
- require 'gorillib/array/sorted_percentile'
3
-
4
- describe Array do
5
- describe '#sorted_percentile' do
6
- context 'with empty' do
7
- it 'returns nil' do
8
- [].sorted_percentile(0.0).should be_nil
9
- end
10
- end
11
-
12
- context 'given any array' do
13
- it 'returns the element closest to the given percentile' do
14
- ("a".."y").to_a.sorted_percentile( 0.0).should == "a"
15
- ("a".."y").to_a.sorted_percentile( 50.0).should == "m"
16
- ("a".."y").to_a.sorted_percentile(100.0).should == "y"
17
- end
18
- end
19
-
20
- # (Please do not define behavior for two elements equally close to
21
- # a given percentile.)
22
-
23
- end
24
- end
@@ -1,28 +0,0 @@
1
- require File.expand_path('../spec_helper', File.dirname(__FILE__))
2
- require 'gorillib/array/sorted_sample'
3
-
4
- describe Array do
5
- describe '#sorted_median' do
6
- context 'with empty' do
7
- it 'returns an empty array' do
8
- [].sorted_sample(1).should be_empty
9
- end
10
- end
11
-
12
- context 'given an undersized array' do
13
- it 'does not return the same element more than once' do
14
- ("a".."z").to_a.sorted_sample(27).should == ("a".."z").to_a
15
- end
16
- end
17
-
18
- context 'given any array' do
19
- it ('returns a sample of the given size as close to evenly ' \
20
- 'distributed over the array as possible') do
21
- sample = (1..100).to_a.sorted_sample(26)
22
- deltas = sample[0..-2].zip(sample[1..-1]).map{|a,b| b-a}
23
- deltas.max.should <= 4
24
- deltas.min.should >= 3
25
- end
26
- end
27
- end
28
- end
@@ -1,99 +0,0 @@
1
- require 'spec_helper'
2
- require 'gorillib/dsl_object'
3
-
4
-
5
- describe DslObject do
6
- let(:test_property) { :yo_momma }
7
- let(:attrs) { { test_property => "is so fat" } }
8
-
9
- after(:each) do
10
- DslObject.send(:remove_method, test_property) if DslObject.method_defined? test_property
11
- DslObject.properties = {}
12
- end
13
-
14
- context DslObject, ".new" do
15
- subject { DslObject.new(attrs) }
16
-
17
- it "transforms an attribute hash given as a constructor argument into properties" do
18
- subject.to_hash.should include attrs
19
- subject.should respond_to test_property
20
- end
21
- end
22
-
23
- context DslObject, ".property" do
24
- subject { DslObject.new(attrs) }
25
-
26
- it "defines a method on a DslObject instance" do
27
- DslObject.property(test_property)
28
- subject.should respond_to test_property
29
- end
30
-
31
- it "allows a default return value to be established for a property" do
32
- DslObject.property(test_property, :default => "is so fat")
33
- subject.send(test_property).should == "is so fat"
34
- end
35
-
36
- let(:existing_method) { :class }
37
- it "does not allow a property to override an existing method" do
38
- DslObject.property(existing_method, :default => "override")
39
- subject.send(existing_method).should_not == "override"
40
- subject.should_not be_instance_variable_defined("@" + existing_method.to_s)
41
- end
42
- end
43
-
44
- context DslObject, "#configure" do
45
- let(:dsl_object) { DslObject.new }
46
- subject { double :context_obj, :delegate => dsl_object }
47
-
48
- it "delegates the configure block to the DslObject instance" do
49
- dsl_object.should_receive(test_property)
50
- subject.should_not_receive(test_property)
51
- subject.delegate.configure { yo_momma "is so fat" }
52
- end
53
- end
54
-
55
- context DslObject, "#to_s" do
56
- subject { DslObject.new(attrs) }
57
-
58
- it "prints to the screen with its class name and properties" do
59
- subject.to_s.should =~ /#{subject.class}.*#{attrs}/
60
- end
61
- end
62
-
63
- context DslObject, "#set" do
64
- subject { DslObject.new(attrs) }
65
-
66
- it "sets a property correctly" do
67
- subject.set(test_property, "is so dumb")
68
- subject.to_hash.should include(test_property => "is so dumb" )
69
- end
70
- end
71
-
72
- context DslObject, "#get" do
73
- subject { DslObject.new(attrs) }
74
-
75
- it "returns a property correctly" do
76
- subject.get(test_property).should == "is so fat"
77
- end
78
- end
79
-
80
- context DslObject, "#set?" do
81
- subject { DslObject.new(attrs) }
82
-
83
- it "correctly determines if a property is set" do
84
- subject.set?(test_property).should be_true
85
- subject.set?(:not_set).should be_false
86
- end
87
- end
88
-
89
- context DslObject, "#unset!" do
90
- subject { DslObject.new(attrs) }
91
-
92
- it "unsets a property" do
93
- subject.unset!(test_property)
94
- subject.set?(test_property).should be_false
95
- end
96
- end
97
- end
98
-
99
-