elektronaut-enumerable_mapper 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2007 Inge Jørgensen
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,63 @@
1
+ = enumerable_mapper
2
+
3
+ enumerable_mapper is a Ruby library that provides a shorthand for
4
+ simple .map/.collect calls on collections. Also supports grouping.
5
+
6
+ == Installation
7
+
8
+ Install from RubyForge:
9
+
10
+ sudo gem install enumerable_mapper
11
+
12
+ Install from GitHub:
13
+
14
+ gem sources -a http://gems.github.com
15
+ sudo gem install elektronaut-enumerable_mapper
16
+
17
+ == Usage
18
+
19
+ require 'enumerable_mapper'
20
+
21
+ # Collecting
22
+ people = Person.find(:all)
23
+ emails = people.collected.email # Equivalent of people.collect{|p| p.email}
24
+
25
+ # Grouping
26
+ people = Person.find(:all)
27
+ people_by_company = people.grouped_by(:company)
28
+ people_by_year = people.grouped_by{|p| p.born_on.year}
29
+
30
+ == API Documentation
31
+
32
+ Is available at http://enum-mapper.rubyforge.org
33
+
34
+ == Source code
35
+
36
+ Is available at http://github.com/elektronaut/enumerable_mapper
37
+
38
+ == Licence
39
+
40
+ (The MIT License)
41
+
42
+ Copyright (c) 2007-2009 Inge Jørgensen
43
+
44
+ Permission is hereby granted, free of charge, to any person
45
+ obtaining a copy of this software and associated documentation
46
+ files (the "Software"), to deal in the Software without
47
+ restriction, including without limitation the rights to use,
48
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
49
+ copies of the Software, and to permit persons to whom the
50
+ Software is furnished to do so, subject to the following
51
+ conditions:
52
+
53
+ The above copyright notice and this permission notice shall be
54
+ included in all copies or substantial portions of the Software.
55
+
56
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
57
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
58
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
59
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
60
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
61
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
62
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
63
+ OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,83 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "enumerable_mapper"
8
+ gem.summary = %Q{enumerable_mapper provides a shorthand for simple .map/.collect calls on collections}
9
+ gem.email = "inge@elektronaut.no"
10
+ gem.homepage = "http://github.com/elektronaut/enumerable_mapper"
11
+ gem.authors = ["Inge Jørgensen"]
12
+ gem.rubyforge_project = 'enum-mapper'
13
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
14
+ end
15
+
16
+ rescue LoadError
17
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
18
+ end
19
+
20
+ require 'rake/testtask'
21
+ Rake::TestTask.new(:test) do |test|
22
+ test.libs << 'lib' << 'test'
23
+ test.pattern = 'test/**/*_test.rb'
24
+ test.verbose = true
25
+ end
26
+
27
+ begin
28
+ require 'rcov/rcovtask'
29
+ Rcov::RcovTask.new do |test|
30
+ test.libs << 'test'
31
+ test.pattern = 'test/**/*_test.rb'
32
+ test.verbose = true
33
+ end
34
+ rescue LoadError
35
+ task :rcov do
36
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
37
+ end
38
+ end
39
+
40
+ begin
41
+ require 'rake/contrib/sshpublisher'
42
+ namespace :rubyforge do
43
+
44
+ desc "Release gem and RDoc documentation to RubyForge"
45
+ task :release => ["rubyforge:release:gem", "rubyforge:release:docs"]
46
+
47
+ namespace :release do
48
+ desc "Publish RDoc to RubyForge."
49
+ task :docs => [:rdoc] do
50
+ config = YAML.load(
51
+ File.read(File.expand_path('~/.rubyforge/user-config.yml'))
52
+ )
53
+
54
+ host = "#{config['username']}@rubyforge.org"
55
+ remote_dir = "/var/www/gforge-projects/enum-mapper/"
56
+ local_dir = 'rdoc'
57
+
58
+ Rake::SshDirPublisher.new(host, remote_dir, local_dir).upload
59
+ end
60
+ end
61
+ end
62
+ rescue LoadError
63
+ puts "Rake SshDirPublisher is unavailable or your rubyforge environment is not configured."
64
+ end
65
+
66
+ task :default => :test
67
+
68
+ require 'rake/rdoctask'
69
+ Rake::RDocTask.new do |rdoc|
70
+ if File.exist?('VERSION.yml')
71
+ config = YAML.load(File.read('VERSION.yml'))
72
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
73
+ else
74
+ version = ""
75
+ end
76
+
77
+ rdoc.rdoc_dir = 'rdoc'
78
+ rdoc.title = "vector2d #{version}"
79
+ rdoc.rdoc_files.include('README*')
80
+ rdoc.rdoc_files.include('lib/**/*.rb')
81
+ end
82
+
83
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
@@ -0,0 +1,34 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+
3
+ module Enumerable
4
+ # An Enumerable::Mapper object works as a proxy for a collection. Any method call
5
+ # on the mapper will be routed to each of the members, and the results will be
6
+ # returned as an array.
7
+ class Mapper
8
+ # Create a new mapper for a collection.
9
+ def initialize( collection )
10
+ @collection = collection
11
+ end
12
+ def method_missing( meth_id, *args) #:nodoc:
13
+ @collection.map{ |a| a.send(meth_id, *args) }
14
+ end
15
+ end
16
+
17
+ # Returns a new mapper for the collection.
18
+ def mapped
19
+ Mapper.new( self )
20
+ end
21
+ alias_method :collected, :mapped
22
+
23
+ # Group collection according to the method name or block given.
24
+ #
25
+ # Examples:
26
+ # Person.find( :all ).grouped_by( :company )
27
+ # Person.find( :all ).grouped_by{ |p| p.born_on.year }
28
+ def grouped_by( method_id=nil )
29
+ raise "No method or block given" unless method_id or block_given?
30
+ groupings = self.map{ |i| ( block_given? ) ? yield( i ) : i.send( method_id ) }.uniq
31
+ groupings.map{ |g| [ g, self.select{ |i| ( ( block_given? ) ? yield( i ) : i.send( method_id ) ) == g } ] }
32
+ end
33
+
34
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class EnumerableMapperTest < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'vector2d'
8
+
9
+ class Test::Unit::TestCase
10
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: elektronaut-enumerable_mapper
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - "Inge J\xC3\xB8rgensen"
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-05-20 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: inge@elektronaut.no
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - LICENSE
24
+ - README.rdoc
25
+ files:
26
+ - .document
27
+ - .gitignore
28
+ - LICENSE
29
+ - README.rdoc
30
+ - Rakefile
31
+ - VERSION
32
+ - lib/enumerable_mapper.rb
33
+ - test/enumerable_mapper_test.rb
34
+ - test/test_helper.rb
35
+ has_rdoc: true
36
+ homepage: http://github.com/elektronaut/enumerable_mapper
37
+ post_install_message:
38
+ rdoc_options:
39
+ - --charset=UTF-8
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: "0"
47
+ version:
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: "0"
53
+ version:
54
+ requirements: []
55
+
56
+ rubyforge_project: enum-mapper
57
+ rubygems_version: 1.2.0
58
+ signing_key:
59
+ specification_version: 2
60
+ summary: enumerable_mapper provides a shorthand for simple .map/.collect calls on collections
61
+ test_files:
62
+ - test/enumerable_mapper_test.rb
63
+ - test/test_helper.rb