gorillib 0.4.0pre → 0.4.1pre
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.
- data/CHANGELOG.md +36 -1
- data/Gemfile +23 -19
- data/Guardfile +1 -1
- data/Rakefile +31 -31
- data/TODO.md +2 -30
- data/VERSION +1 -1
- data/examples/builder/ironfan.rb +4 -4
- data/gorillib.gemspec +40 -25
- data/lib/gorillib/array/average.rb +13 -0
- data/lib/gorillib/array/sorted_median.rb +11 -0
- data/lib/gorillib/array/sorted_percentile.rb +11 -0
- data/lib/gorillib/array/sorted_sample.rb +12 -0
- data/lib/gorillib/builder.rb +8 -14
- data/lib/gorillib/collection/has_collection.rb +31 -31
- data/lib/gorillib/collection/list_collection.rb +58 -0
- data/lib/gorillib/collection/model_collection.rb +63 -0
- data/lib/gorillib/collection.rb +57 -85
- data/lib/gorillib/logger/log.rb +26 -22
- data/lib/gorillib/model/base.rb +52 -39
- data/lib/gorillib/model/doc_string.rb +15 -0
- data/lib/gorillib/model/factories.rb +56 -61
- data/lib/gorillib/model/lint.rb +24 -0
- data/lib/gorillib/model/serialization.rb +12 -2
- data/lib/gorillib/model/validate.rb +2 -2
- data/lib/gorillib/pathname.rb +21 -6
- data/lib/gorillib/some.rb +2 -0
- data/lib/gorillib/type/extended.rb +0 -2
- data/lib/gorillib/type/url.rb +9 -0
- data/lib/gorillib/utils/console.rb +4 -1
- data/notes/HOWTO.md +22 -0
- data/notes/bucket.md +155 -0
- data/notes/builder.md +170 -0
- data/notes/collection.md +81 -0
- data/notes/factories.md +86 -0
- data/notes/model-overlay.md +209 -0
- data/notes/model.md +135 -0
- data/notes/structured-data-classes.md +127 -0
- data/spec/array/average_spec.rb +24 -0
- data/spec/array/sorted_median_spec.rb +18 -0
- data/spec/array/sorted_percentile_spec.rb +24 -0
- data/spec/array/sorted_sample_spec.rb +28 -0
- data/spec/gorillib/builder_spec.rb +46 -28
- data/spec/gorillib/collection_spec.rb +195 -10
- data/spec/gorillib/model/lint_spec.rb +28 -0
- data/spec/gorillib/model/record/factories_spec.rb +27 -13
- data/spec/gorillib/model/serialization_spec.rb +3 -5
- data/spec/gorillib/model_spec.rb +86 -104
- data/spec/spec_helper.rb +2 -1
- data/spec/support/gorillib_test_helpers.rb +83 -7
- data/spec/support/model_test_helpers.rb +9 -28
- metadata +52 -44
- data/lib/gorillib/configurable.rb +0 -28
- data/spec/gorillib/configurable_spec.rb +0 -62
- data/spec/support/shared_examples/included_module.rb +0 -20
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,41 @@
|
|
1
1
|
## Version 1.0
|
2
2
|
|
3
|
-
|
3
|
+
|
4
|
+
### 2012-06 - Version 1.0.1-pre: First wave of refactors
|
5
|
+
|
6
|
+
**model**:
|
7
|
+
|
8
|
+
* `receive!` is now called from the initiailizer.
|
9
|
+
|
10
|
+
* the initializer now takes `(*positional_args, attrs)`, assembles the `positional_args` into the attrs, and hands them to `receive!`.
|
11
|
+
|
12
|
+
* the way you get a "magic get-set attribute" in builder is by saying `magic`, not `field` -- `field` means the same thing as it does in model.
|
13
|
+
|
14
|
+
**collection**:
|
15
|
+
|
16
|
+
Gorillib::Collection has been broken up as follows:
|
17
|
+
|
18
|
+
* A generic collection stores objects uniquely, in the order added. It responds to:
|
19
|
+
- receive!, values, to_a, each and each_value;
|
20
|
+
- length, size, empty?, blank?
|
21
|
+
|
22
|
+
* `Gorillib::Collection` additionally lets you store and retrieve things by label:
|
23
|
+
- [], []=, include?, fetch, delete, each_pair, to_hash.
|
24
|
+
|
25
|
+
* `Gorillib::ModelCollection` adds:
|
26
|
+
- `key_method`: called on objects to get their key; `to_key` by default.
|
27
|
+
- `factory`: generates new objects, converts received objects
|
28
|
+
- `<<`: adds object under its `key_method` key
|
29
|
+
- `receive!`s an array by auto-keying the elements, or a hash by trusting what you give it
|
30
|
+
- `update_or_create: if absent, creates object with given attributes and
|
31
|
+
`key_method => key`; if present, updates with given attributes.
|
32
|
+
|
33
|
+
what this means for you:
|
34
|
+
* `Collection` no longer has factory functionality -- that is now in `ModelCollection`.
|
35
|
+
* The signature of `ModelCollection#initialize` is `initialize(key_meth, factory)` -- the reverse of what was.
|
36
|
+
|
37
|
+
|
38
|
+
### 2012-04 - Version 1.0.0-pre: DSL Magic
|
4
39
|
|
5
40
|
#### New functionality
|
6
41
|
|
data/Gemfile
CHANGED
@@ -1,32 +1,36 @@
|
|
1
1
|
source "http://rubygems.org"
|
2
2
|
|
3
|
-
gem
|
4
|
-
gem 'json'
|
5
|
-
gem 'configliere', '>= 0.4.13'
|
3
|
+
gem 'multi_json', ">= 1.1"
|
6
4
|
|
5
|
+
# Only gems that you want listed as development dependencies in the gemspec
|
7
6
|
group :development do
|
8
|
-
gem
|
9
|
-
gem
|
10
|
-
gem
|
7
|
+
gem 'bundler', "~> 1.1"
|
8
|
+
gem 'rake'
|
9
|
+
gem 'oj', ">= 1.2"
|
10
|
+
gem 'json', :platform => :jruby
|
11
|
+
end
|
12
|
+
|
13
|
+
# Gems you would use if hacking on this gem (rather than with it)
|
14
|
+
group :support do
|
15
|
+
gem 'jeweler', ">= 1.6"
|
16
|
+
gem 'pry'
|
11
17
|
end
|
12
18
|
|
13
19
|
group :docs do
|
14
|
-
gem
|
15
|
-
gem
|
20
|
+
gem 'yard', ">= 0.7"
|
21
|
+
gem 'redcarpet', ">= 2.1"
|
16
22
|
end
|
17
23
|
|
24
|
+
# Gems for testing and coverage
|
18
25
|
group :test do
|
19
|
-
gem
|
26
|
+
gem 'rspec', "~> 2.8"
|
27
|
+
gem 'simplecov', ">= 0.5", :platform => :ruby_19
|
28
|
+
#
|
29
|
+
gem 'guard', ">= 1.0"
|
30
|
+
gem 'guard-rspec', ">= 0.6"
|
31
|
+
gem 'guard-yard'
|
32
|
+
#
|
20
33
|
if RUBY_PLATFORM.include?('darwin')
|
21
|
-
gem 'rb-fsevent', "
|
22
|
-
# gem 'growl', "~> 1"
|
23
|
-
# gem 'ruby_gntp'
|
34
|
+
gem 'rb-fsevent', ">= 0.9"
|
24
35
|
end
|
25
|
-
|
26
|
-
gem 'guard', "~> 1"
|
27
|
-
gem 'guard-rspec'
|
28
|
-
gem 'guard-yard'
|
29
|
-
gem 'guard-process'
|
30
|
-
|
31
|
-
# gem 'simplecov', ">= 0.5", :platform => :ruby_19
|
32
36
|
end
|
data/Guardfile
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
# '--format doc' for more verbose, --format progress for less
|
9
9
|
format = "progress"
|
10
10
|
# '--tag record_spec' to only run tests tagged :record_spec
|
11
|
-
tags = %w[
|
11
|
+
tags = %w[ ] # builder_spec example_spec model_spec
|
12
12
|
|
13
13
|
guard 'rspec', :version => 2, :cli => "--format #{format} #{ tags.map{|tag| "--tag #{tag}"}.join(" ") }" do
|
14
14
|
watch(%r{^spec/.+_spec\.rb$})
|
data/Rakefile
CHANGED
@@ -1,36 +1,35 @@
|
|
1
1
|
require 'rubygems' unless defined?(Gem)
|
2
2
|
require 'bundler'
|
3
3
|
begin
|
4
|
-
Bundler.setup(:default, :development, :test)
|
4
|
+
Bundler.setup(:default, :development, :support, :test)
|
5
5
|
rescue Bundler::BundlerError => e
|
6
6
|
$stderr.puts e.message
|
7
7
|
$stderr.puts "Run `bundle install` to install missing gems"
|
8
8
|
exit e.status_code
|
9
9
|
end
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
#
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
# Jeweler::RubygemsDotOrgTasks.new
|
10
|
+
require 'rake'
|
11
|
+
|
12
|
+
require 'jeweler'
|
13
|
+
Jeweler::Tasks.new do |gem|
|
14
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
|
+
gem.name = "gorillib"
|
16
|
+
gem.homepage = "http://infochimps.com/labs"
|
17
|
+
gem.license = "MIT"
|
18
|
+
gem.summary = %Q{include only what you need. No dependencies, no creep}
|
19
|
+
gem.description = %Q{Gorillib: infochimps lightweight subset of ruby convenience methods}
|
20
|
+
gem.email = "coders@infochimps.org"
|
21
|
+
gem.authors = ["Infochimps"]
|
22
|
+
|
23
|
+
ignores = File.readlines(".gitignore").grep(/^[^#]\S+/).map{|s| s.chomp }
|
24
|
+
dotfiles = [".gemtest", ".gitignore", ".rspec", ".yardopts"]
|
25
|
+
gem.files = dotfiles + Dir["**/*"].
|
26
|
+
reject{|f| f =~ %r{^(vendor|coverage)/} }.
|
27
|
+
reject{|f| File.directory?(f) }.
|
28
|
+
reject{|f| ignores.any?{|i| File.fnmatch(i, f) || File.fnmatch(i+'/**/*', f) || File.fnmatch(i+'/*', f) } }
|
29
|
+
gem.test_files = gem.files.grep(/^spec\//)
|
30
|
+
gem.require_paths = ['lib']
|
31
|
+
end
|
32
|
+
Jeweler::RubygemsDotOrgTasks.new
|
34
33
|
|
35
34
|
require 'rspec/core'
|
36
35
|
require 'rspec/core/rake_task'
|
@@ -39,12 +38,13 @@ RSpec::Core::RakeTask.new(:spec) do |spec|
|
|
39
38
|
spec.pattern = FileList['spec/**/*_spec.rb']
|
40
39
|
end
|
41
40
|
|
42
|
-
#
|
43
|
-
#
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
41
|
+
# if rcov shits the bed with ruby 1.9, see
|
42
|
+
# https://github.com/relevance/rcov/issues/31
|
43
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
44
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
45
|
+
spec.rcov = true
|
46
|
+
spec.rcov_opts = %w[ --exclude .rvm --no-comments --text-summary]
|
47
|
+
end
|
48
48
|
|
49
49
|
require 'yard'
|
50
50
|
YARD::Rake::YardocTask.new do
|
data/TODO.md
CHANGED
@@ -1,32 +1,4 @@
|
|
1
1
|
|
2
|
-
We need a convention for detailed inspection
|
2
|
+
* We need a convention for detailed inspection
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
FIXME: registry creation
|
7
|
-
|
8
|
-
FIXME: field creation is kinda gnarly
|
9
|
-
|
10
|
-
FIXME: number of things we have to import has grown large
|
11
|
-
|
12
|
-
### Builder
|
13
|
-
|
14
|
-
FIXME: read_attribute / write_attribute contract?
|
15
|
-
FIXME: naming of collection members -- who does it?
|
16
|
-
|
17
|
-
FIXME: collection factory stuff is all screwy
|
18
|
-
|
19
|
-
|
20
|
-
tester for a collection item -- `has_facet?` not `facet?`
|
21
|
-
|
22
|
-
### Collection
|
23
|
-
|
24
|
-
FIXME: factory stuff is all screwy
|
25
|
-
FIXME: conversion stuff screwy to some extent
|
26
|
-
|
27
|
-
FIXME: Should a collection be enumerable, and how?
|
28
|
-
|
29
|
-
|
30
|
-
repeated logic in has_collection and builder stuff ...
|
31
|
-
should you be able to decorate anything with a decorator?
|
32
|
-
with a field?
|
4
|
+
* Pathname.path_to should be absolute path, not relative
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.1
|
data/examples/builder/ironfan.rb
CHANGED
@@ -7,7 +7,7 @@ module Gorillib::Test
|
|
7
7
|
|
8
8
|
class IronfanBuilder
|
9
9
|
include Gorillib::FancyBuilder
|
10
|
-
|
10
|
+
magic :name, Symbol
|
11
11
|
|
12
12
|
end
|
13
13
|
class ComputeBuilder < IronfanBuilder; end
|
@@ -38,7 +38,7 @@ module Gorillib::Test
|
|
38
38
|
|
39
39
|
|
40
40
|
class ComputeBuilder < IronfanBuilder
|
41
|
-
|
41
|
+
magic :environment, Symbol
|
42
42
|
collection :clouds, Cloud
|
43
43
|
collection :volumes, Volume
|
44
44
|
collection :components, Component
|
@@ -72,7 +72,7 @@ module Gorillib::Test
|
|
72
72
|
class Facet < ComputeBuilder
|
73
73
|
belongs_to :cluster, Cluster
|
74
74
|
collection :servers, Server
|
75
|
-
|
75
|
+
magic :instances, Integer, :doc => 'number of servers to instantiate for this machine'
|
76
76
|
end
|
77
77
|
|
78
78
|
class Server < ComputeBuilder
|
@@ -89,7 +89,7 @@ module Gorillib::Test
|
|
89
89
|
end
|
90
90
|
|
91
91
|
class Component < IronfanBuilder
|
92
|
-
|
92
|
+
magic :discovers, Array, :of => :whatever, :doc => 'components this one discovers. Can be used to intelligently generate security groups, add client components, etc'
|
93
93
|
end
|
94
94
|
|
95
95
|
class SecurityGroup < IronfanBuilder
|
data/gorillib.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "gorillib"
|
8
|
-
s.version = "0.4.
|
8
|
+
s.version = "0.4.1pre"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Infochimps"]
|
12
|
-
s.date = "2012-
|
12
|
+
s.date = "2012-06-27"
|
13
13
|
s.description = "Gorillib: infochimps lightweight subset of ruby convenience methods"
|
14
14
|
s.email = "coders@infochimps.org"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -33,17 +33,22 @@ Gem::Specification.new do |s|
|
|
33
33
|
"gorillib.gemspec",
|
34
34
|
"lib/alt/kernel/call_stack.rb",
|
35
35
|
"lib/gorillib.rb",
|
36
|
+
"lib/gorillib/array/average.rb",
|
36
37
|
"lib/gorillib/array/compact_blank.rb",
|
37
38
|
"lib/gorillib/array/deep_compact.rb",
|
38
39
|
"lib/gorillib/array/extract_options.rb",
|
39
40
|
"lib/gorillib/array/random.rb",
|
41
|
+
"lib/gorillib/array/sorted_median.rb",
|
42
|
+
"lib/gorillib/array/sorted_percentile.rb",
|
43
|
+
"lib/gorillib/array/sorted_sample.rb",
|
40
44
|
"lib/gorillib/array/wrap.rb",
|
41
45
|
"lib/gorillib/base.rb",
|
42
46
|
"lib/gorillib/builder.rb",
|
43
47
|
"lib/gorillib/builder/field.rb",
|
44
48
|
"lib/gorillib/collection.rb",
|
45
49
|
"lib/gorillib/collection/has_collection.rb",
|
46
|
-
"lib/gorillib/
|
50
|
+
"lib/gorillib/collection/list_collection.rb",
|
51
|
+
"lib/gorillib/collection/model_collection.rb",
|
47
52
|
"lib/gorillib/datetime/parse.rb",
|
48
53
|
"lib/gorillib/datetime/to_flat.rb",
|
49
54
|
"lib/gorillib/enumerable/sum.rb",
|
@@ -82,9 +87,11 @@ Gem::Specification.new do |s|
|
|
82
87
|
"lib/gorillib/model/active_model_shim.rb",
|
83
88
|
"lib/gorillib/model/base.rb",
|
84
89
|
"lib/gorillib/model/defaults.rb",
|
90
|
+
"lib/gorillib/model/doc_string.rb",
|
85
91
|
"lib/gorillib/model/errors.rb",
|
86
92
|
"lib/gorillib/model/factories.rb",
|
87
93
|
"lib/gorillib/model/field.rb",
|
94
|
+
"lib/gorillib/model/lint.rb",
|
88
95
|
"lib/gorillib/model/named_schema.rb",
|
89
96
|
"lib/gorillib/model/overlay.rb",
|
90
97
|
"lib/gorillib/model/record_schema.rb",
|
@@ -104,10 +111,23 @@ Gem::Specification.new do |s|
|
|
104
111
|
"lib/gorillib/string/simple_inflector.rb",
|
105
112
|
"lib/gorillib/string/truncate.rb",
|
106
113
|
"lib/gorillib/type/extended.rb",
|
114
|
+
"lib/gorillib/type/url.rb",
|
107
115
|
"lib/gorillib/utils/capture_output.rb",
|
108
116
|
"lib/gorillib/utils/console.rb",
|
109
117
|
"lib/gorillib/utils/nuke_constants.rb",
|
110
118
|
"lib/gorillib/utils/stub_module.rb",
|
119
|
+
"notes/HOWTO.md",
|
120
|
+
"notes/bucket.md",
|
121
|
+
"notes/builder.md",
|
122
|
+
"notes/collection.md",
|
123
|
+
"notes/factories.md",
|
124
|
+
"notes/model-overlay.md",
|
125
|
+
"notes/model.md",
|
126
|
+
"notes/structured-data-classes.md",
|
127
|
+
"spec/array/average_spec.rb",
|
128
|
+
"spec/array/sorted_median_spec.rb",
|
129
|
+
"spec/array/sorted_percentile_spec.rb",
|
130
|
+
"spec/array/sorted_sample_spec.rb",
|
111
131
|
"spec/examples/builder/ironfan_spec.rb",
|
112
132
|
"spec/extlib/hash_spec.rb",
|
113
133
|
"spec/extlib/mash_spec.rb",
|
@@ -115,7 +135,6 @@ Gem::Specification.new do |s|
|
|
115
135
|
"spec/gorillib/array/extract_options_spec.rb",
|
116
136
|
"spec/gorillib/builder_spec.rb",
|
117
137
|
"spec/gorillib/collection_spec.rb",
|
118
|
-
"spec/gorillib/configurable_spec.rb",
|
119
138
|
"spec/gorillib/datetime/parse_spec.rb",
|
120
139
|
"spec/gorillib/datetime/to_flat_spec.rb",
|
121
140
|
"spec/gorillib/enumerable/sum_spec.rb",
|
@@ -137,6 +156,7 @@ Gem::Specification.new do |s|
|
|
137
156
|
"spec/gorillib/metaprogramming/class_attribute_spec.rb",
|
138
157
|
"spec/gorillib/metaprogramming/delegation_spec.rb",
|
139
158
|
"spec/gorillib/metaprogramming/singleton_class_spec.rb",
|
159
|
+
"spec/gorillib/model/lint_spec.rb",
|
140
160
|
"spec/gorillib/model/record/defaults_spec.rb",
|
141
161
|
"spec/gorillib/model/record/factories_spec.rb",
|
142
162
|
"spec/gorillib/model/record/overlay_spec.rb",
|
@@ -165,41 +185,36 @@ Gem::Specification.new do |s|
|
|
165
185
|
"spec/support/matchers/be_hash_eql.rb",
|
166
186
|
"spec/support/matchers/enumerate_method.rb",
|
167
187
|
"spec/support/matchers/evaluate_to_true.rb",
|
168
|
-
"spec/support/model_test_helpers.rb"
|
169
|
-
"spec/support/shared_examples/included_module.rb"
|
188
|
+
"spec/support/model_test_helpers.rb"
|
170
189
|
]
|
171
190
|
s.homepage = "http://infochimps.com/labs"
|
172
191
|
s.licenses = ["MIT"]
|
173
192
|
s.require_paths = ["lib"]
|
174
|
-
s.rubygems_version = "1.8.
|
193
|
+
s.rubygems_version = "1.8.11"
|
175
194
|
s.summary = "include only what you need. No dependencies, no creep"
|
176
|
-
s.test_files = ["spec/examples/builder/ironfan_spec.rb", "spec/extlib/hash_spec.rb", "spec/extlib/mash_spec.rb", "spec/gorillib/array/compact_blank_spec.rb", "spec/gorillib/array/extract_options_spec.rb", "spec/gorillib/builder_spec.rb", "spec/gorillib/collection_spec.rb", "spec/gorillib/
|
195
|
+
s.test_files = ["spec/array/average_spec.rb", "spec/array/sorted_median_spec.rb", "spec/array/sorted_percentile_spec.rb", "spec/array/sorted_sample_spec.rb", "spec/examples/builder/ironfan_spec.rb", "spec/extlib/hash_spec.rb", "spec/extlib/mash_spec.rb", "spec/gorillib/array/compact_blank_spec.rb", "spec/gorillib/array/extract_options_spec.rb", "spec/gorillib/builder_spec.rb", "spec/gorillib/collection_spec.rb", "spec/gorillib/datetime/parse_spec.rb", "spec/gorillib/datetime/to_flat_spec.rb", "spec/gorillib/enumerable/sum_spec.rb", "spec/gorillib/exception/raisers_spec.rb", "spec/gorillib/hash/compact_spec.rb", "spec/gorillib/hash/deep_compact_spec.rb", "spec/gorillib/hash/deep_merge_spec.rb", "spec/gorillib/hash/keys_spec.rb", "spec/gorillib/hash/reverse_merge_spec.rb", "spec/gorillib/hash/slice_spec.rb", "spec/gorillib/hash/zip_spec.rb", "spec/gorillib/hashlike/behave_same_as_hash_spec.rb", "spec/gorillib/hashlike/deep_hash_spec.rb", "spec/gorillib/hashlike/hashlike_behavior_spec.rb", "spec/gorillib/hashlike/hashlike_via_accessors_spec.rb", "spec/gorillib/hashlike_spec.rb", "spec/gorillib/logger/log_spec.rb", "spec/gorillib/metaprogramming/aliasing_spec.rb", "spec/gorillib/metaprogramming/class_attribute_spec.rb", "spec/gorillib/metaprogramming/delegation_spec.rb", "spec/gorillib/metaprogramming/singleton_class_spec.rb", "spec/gorillib/model/lint_spec.rb", "spec/gorillib/model/record/defaults_spec.rb", "spec/gorillib/model/record/factories_spec.rb", "spec/gorillib/model/record/overlay_spec.rb", "spec/gorillib/model/serialization_spec.rb", "spec/gorillib/model_spec.rb", "spec/gorillib/numeric/clamp_spec.rb", "spec/gorillib/object/blank_spec.rb", "spec/gorillib/object/try_dup_spec.rb", "spec/gorillib/object/try_spec.rb", "spec/gorillib/pathname_spec.rb", "spec/gorillib/string/constantize_spec.rb", "spec/gorillib/string/human_spec.rb", "spec/gorillib/string/inflections_spec.rb", "spec/gorillib/string/inflector_test_cases.rb", "spec/gorillib/string/truncate_spec.rb", "spec/gorillib/type/extended_spec.rb", "spec/gorillib/utils/capture_output_spec.rb", "spec/spec_helper.rb", "spec/support/gorillib_test_helpers.rb", "spec/support/hashlike_fuzzing_helper.rb", "spec/support/hashlike_helper.rb", "spec/support/hashlike_struct_helper.rb", "spec/support/hashlike_via_delegation.rb", "spec/support/kcode_test_helper.rb", "spec/support/matchers/be_array_eql.rb", "spec/support/matchers/be_hash_eql.rb", "spec/support/matchers/enumerate_method.rb", "spec/support/matchers/evaluate_to_true.rb", "spec/support/model_test_helpers.rb"]
|
177
196
|
|
178
197
|
if s.respond_to? :specification_version then
|
179
198
|
s.specification_version = 3
|
180
199
|
|
181
200
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
182
|
-
s.add_runtime_dependency(%q<multi_json>, ["
|
183
|
-
s.
|
184
|
-
s.
|
185
|
-
s.add_development_dependency(%q<
|
186
|
-
s.add_development_dependency(%q<
|
187
|
-
s.add_development_dependency(%q<jeweler>, ["~> 1.6"])
|
201
|
+
s.add_runtime_dependency(%q<multi_json>, [">= 1.1"])
|
202
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.1"])
|
203
|
+
s.add_development_dependency(%q<rake>, [">= 0"])
|
204
|
+
s.add_development_dependency(%q<oj>, [">= 1.2"])
|
205
|
+
s.add_development_dependency(%q<json>, [">= 0"])
|
188
206
|
else
|
189
|
-
s.add_dependency(%q<multi_json>, ["
|
207
|
+
s.add_dependency(%q<multi_json>, [">= 1.1"])
|
208
|
+
s.add_dependency(%q<bundler>, ["~> 1.1"])
|
209
|
+
s.add_dependency(%q<rake>, [">= 0"])
|
210
|
+
s.add_dependency(%q<oj>, [">= 1.2"])
|
190
211
|
s.add_dependency(%q<json>, [">= 0"])
|
191
|
-
s.add_dependency(%q<configliere>, [">= 0.4.13"])
|
192
|
-
s.add_dependency(%q<bundler>, ["~> 1"])
|
193
|
-
s.add_dependency(%q<pry>, [">= 0"])
|
194
|
-
s.add_dependency(%q<jeweler>, ["~> 1.6"])
|
195
212
|
end
|
196
213
|
else
|
197
|
-
s.add_dependency(%q<multi_json>, ["
|
214
|
+
s.add_dependency(%q<multi_json>, [">= 1.1"])
|
215
|
+
s.add_dependency(%q<bundler>, ["~> 1.1"])
|
216
|
+
s.add_dependency(%q<rake>, [">= 0"])
|
217
|
+
s.add_dependency(%q<oj>, [">= 1.2"])
|
198
218
|
s.add_dependency(%q<json>, [">= 0"])
|
199
|
-
s.add_dependency(%q<configliere>, [">= 0.4.13"])
|
200
|
-
s.add_dependency(%q<bundler>, ["~> 1"])
|
201
|
-
s.add_dependency(%q<pry>, [">= 0"])
|
202
|
-
s.add_dependency(%q<jeweler>, ["~> 1.6"])
|
203
219
|
end
|
204
220
|
end
|
205
|
-
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class Array
|
2
|
+
#
|
3
|
+
# Return the average of my elements.
|
4
|
+
#
|
5
|
+
# precondition: Each element must be convertible to a float.
|
6
|
+
#
|
7
|
+
def average
|
8
|
+
return nil if empty?
|
9
|
+
raise ArgumentError, "Couldn't convert all elements to float!" unless
|
10
|
+
all?{|e| e.methods.index :to_f}
|
11
|
+
return map(&:to_f).inject(:+) / size
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class Array
|
2
|
+
#
|
3
|
+
# Returns the middle element of odd-sized arrays. For even arrays,
|
4
|
+
# it will return one of the two middle elements. Precisely which is
|
5
|
+
# undefined, except that it will consistently return one or the
|
6
|
+
# other.
|
7
|
+
#
|
8
|
+
def sorted_median
|
9
|
+
return self[(size - 1) * 0.5]
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class Array
|
2
|
+
#
|
3
|
+
# Returns the element at the position closest to the given
|
4
|
+
# percentile. For example, sorted_percentile 0.0 will return the
|
5
|
+
# first element and sorted_percentile 100.0 will return the last
|
6
|
+
# element.
|
7
|
+
#
|
8
|
+
def sorted_percentile percentile
|
9
|
+
return self[(size - 1) * percentile / 100.0]
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class Array
|
2
|
+
#
|
3
|
+
# Returns the middle element of odd-sized arrays. For even arrays,
|
4
|
+
# it will return one of the two middle elements. Precisely which is
|
5
|
+
# undefined, except that it will consistently return one or the
|
6
|
+
# other.
|
7
|
+
#
|
8
|
+
def sorted_sample num
|
9
|
+
return [] if empty?
|
10
|
+
(1..num).map{|i| self[(size - 1) * i / (num)]}.uniq
|
11
|
+
end
|
12
|
+
end
|
data/lib/gorillib/builder.rb
CHANGED
@@ -1,15 +1,12 @@
|
|
1
1
|
require 'gorillib/string/simple_inflector'
|
2
2
|
require 'gorillib/model'
|
3
|
+
require 'gorillib/collection/model_collection'
|
3
4
|
|
4
5
|
module Gorillib
|
5
6
|
module Builder
|
6
7
|
extend Gorillib::Concern
|
7
8
|
include Gorillib::Model
|
8
9
|
|
9
|
-
def initialize(attrs={}, &block)
|
10
|
-
receive!(attrs, &block)
|
11
|
-
end
|
12
|
-
|
13
10
|
def receive!(*args, &block)
|
14
11
|
super(*args)
|
15
12
|
if block_given?
|
@@ -103,20 +100,17 @@ module Gorillib
|
|
103
100
|
module ClassMethods
|
104
101
|
include Gorillib::Model::ClassMethods
|
105
102
|
|
106
|
-
def
|
107
|
-
|
103
|
+
def magic(field_name, type, options={})
|
104
|
+
field(field_name, type, {:field_type => ::Gorillib::Builder::GetsetField}.merge(options))
|
108
105
|
end
|
109
106
|
def member(field_name, type, options={})
|
110
107
|
field(field_name, type, {:field_type => ::Gorillib::Builder::MemberField}.merge(options))
|
111
108
|
end
|
112
109
|
def collection(field_name, item_type, options={})
|
113
|
-
field(field_name, Gorillib::
|
110
|
+
field(field_name, Gorillib::ModelCollection, {
|
114
111
|
:item_type => item_type,
|
115
112
|
:field_type => ::Gorillib::Builder::CollectionField}.merge(options))
|
116
113
|
end
|
117
|
-
def simple_field(field_name, type, options={})
|
118
|
-
field(field_name, type, {:field_type => ::Gorillib::Model::Field}.merge(options))
|
119
|
-
end
|
120
114
|
|
121
115
|
protected
|
122
116
|
|
@@ -178,14 +172,14 @@ module Gorillib
|
|
178
172
|
include Gorillib::Builder
|
179
173
|
|
180
174
|
included do |base|
|
181
|
-
base.
|
175
|
+
base.magic :name, Symbol
|
182
176
|
end
|
183
177
|
|
184
178
|
module ClassMethods
|
185
179
|
include Gorillib::Builder::ClassMethods
|
186
180
|
|
187
181
|
def belongs_to(field_name, type, options={})
|
188
|
-
field =
|
182
|
+
field = member(field_name, type)
|
189
183
|
define_meta_module_method "#{field.name}_name" do
|
190
184
|
val = getset_member(field) or return nil
|
191
185
|
val.name
|
@@ -195,7 +189,7 @@ module Gorillib
|
|
195
189
|
|
196
190
|
def option(field_name, options={})
|
197
191
|
type = options.delete(:type){ Whatever }
|
198
|
-
|
192
|
+
magic(field_name, type)
|
199
193
|
end
|
200
194
|
|
201
195
|
def collects(type, clxn_name)
|
@@ -243,7 +237,7 @@ module Gorillib
|
|
243
237
|
|
244
238
|
def inscribe_methods(model)
|
245
239
|
item_type = self.item_type
|
246
|
-
self.default = ->{ Gorillib::
|
240
|
+
self.default = ->{ Gorillib::ModelCollection.new(nil, item_type) }
|
247
241
|
raise "Plural and singular names must differ: #{self.plural_name}" if (singular_name == plural_name)
|
248
242
|
#
|
249
243
|
@visibilities[:writer] = false
|
@@ -1,31 +1,31 @@
|
|
1
|
-
module Gorillib
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
end
|
1
|
+
# module Gorillib
|
2
|
+
# class Collection
|
3
|
+
# module HasCollection
|
4
|
+
#
|
5
|
+
# def has_collection(clxn_name, type, key_method=:name)
|
6
|
+
# plural_name = clxn_name
|
7
|
+
# singular_name = Gorillib::Inflector.singularize(clxn_name.to_s).to_sym
|
8
|
+
#
|
9
|
+
# instance_variable_set("@#{plural_name}", Gorillib::Collection.new(type, key_method))
|
10
|
+
#
|
11
|
+
# define_singleton_method(plural_name) do
|
12
|
+
# instance_variable_get("@#{plural_name}") if instance_variable_defined?("@#{plural_name}")
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
# define_singleton_method(singular_name) do |item_key, attrs={}, options={}, &block|
|
16
|
+
# collection = instance_variable_get("@#{clxn_name}")
|
17
|
+
# val = collection.fetch(item_key) do
|
18
|
+
# attrs.merge!(key_method => item_key, :owner => self) if attrs.respond_to?(:merge!)
|
19
|
+
# factory = options.fetch(:factory){ type }
|
20
|
+
# new_val = factory.receive(attrs)
|
21
|
+
# collection << new_val
|
22
|
+
# new_val
|
23
|
+
# end
|
24
|
+
# val.instance_exec(&block) if block
|
25
|
+
# val
|
26
|
+
# end
|
27
|
+
# end
|
28
|
+
#
|
29
|
+
# end
|
30
|
+
# end
|
31
|
+
# end
|