hashed 0.0.1

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/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in hashed.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (C) 2011 by Rinat Shaykhutdinov
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,14 @@
1
+ # Hashed
2
+
3
+ Provides `hashed` method to ActiveRecord objects set that return hash where keys is value of some field in dataset (def. "id").
4
+
5
+ ```ruby
6
+ gem "hashed"
7
+ ```
8
+
9
+ Then run `bundle install` and simple use it!
10
+
11
+ ```ruby
12
+ Categories.active.hashed # equal to Categories.active.hashed(:id)
13
+ Categories.active.hashed(:create_at)
14
+ ```
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/hashed.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "hashed/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "hashed"
7
+ s.version = Hashed::VERSION
8
+ s.authors = ["Rinat Shaykhutdinov"]
9
+ s.email = ["rinat.crone@gmail.com"]
10
+ s.homepage = "https://github.com/cronych/hashed"
11
+ s.summary = %q{Makes hash from AR objects collection}
12
+ s.description = %q{Makes hash from AR objects collection}
13
+
14
+ s.rubyforge_project = "hashed"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_development_dependency "rspec"
22
+ s.add_development_dependency "sqlite3-ruby"
23
+ s.add_dependency "activerecord", "~> 3.0"
24
+ end
@@ -0,0 +1,3 @@
1
+ module Hashed
2
+ VERSION = "0.0.1"
3
+ end
data/lib/hashed.rb ADDED
@@ -0,0 +1,13 @@
1
+ require "hashed/version"
2
+ require "active_record"
3
+
4
+ module Hashed
5
+ def hashed(field = :id)
6
+ result = {}
7
+
8
+ self.all.each { |row| result[row.send(field)] = row }
9
+ result
10
+ end
11
+ end
12
+
13
+ ActiveRecord::Base.extend Hashed
@@ -0,0 +1,13 @@
1
+ require "spec_helper"
2
+
3
+ describe Hashed do
4
+ it "return id-keyed hash with objects" do
5
+ Post.hashed.should eq({ 1 => Post.find(1), 2 => Post.find(2) })
6
+ end
7
+
8
+ it "return date-keyed hash with objects" do
9
+ Post.hashed(:created_at).should eq({ Post.find(1).created_at => Post.find(1),
10
+ Post.find(2).created_at => Post.find(2) })
11
+ end
12
+
13
+ end
@@ -0,0 +1,7 @@
1
+ require "hashed"
2
+
3
+ ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: "#{File.dirname(__FILE__)}/hashed.sqlite3")
4
+
5
+ load "#{File.dirname(__FILE__)}/support/schema.rb"
6
+ load "#{File.dirname(__FILE__)}/support/models.rb"
7
+ load "#{File.dirname(__FILE__)}/support/data.rb"
@@ -0,0 +1 @@
1
+ 2.times{ Post.create }
@@ -0,0 +1,2 @@
1
+ class Post < ActiveRecord::Base
2
+ end
@@ -0,0 +1,7 @@
1
+ ActiveRecord::Schema.define do
2
+ self.verbose = false
3
+
4
+ create_table :posts, force: true do |t|
5
+ t.timestamps
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hashed
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Rinat Shaykhutdinov
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-12-01 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &70195897605540 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70195897605540
25
+ - !ruby/object:Gem::Dependency
26
+ name: sqlite3-ruby
27
+ requirement: &70195897605120 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70195897605120
36
+ - !ruby/object:Gem::Dependency
37
+ name: activerecord
38
+ requirement: &70195897604620 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: '3.0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70195897604620
47
+ description: Makes hash from AR objects collection
48
+ email:
49
+ - rinat.crone@gmail.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - .rspec
56
+ - Gemfile
57
+ - LICENSE
58
+ - README.md
59
+ - Rakefile
60
+ - hashed.gemspec
61
+ - lib/hashed.rb
62
+ - lib/hashed/version.rb
63
+ - spec/hashed/hashed_spec.rb
64
+ - spec/spec_helper.rb
65
+ - spec/support/data.rb
66
+ - spec/support/models.rb
67
+ - spec/support/schema.rb
68
+ homepage: https://github.com/cronych/hashed
69
+ licenses: []
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements: []
87
+ rubyforge_project: hashed
88
+ rubygems_version: 1.8.10
89
+ signing_key:
90
+ specification_version: 3
91
+ summary: Makes hash from AR objects collection
92
+ test_files:
93
+ - spec/hashed/hashed_spec.rb
94
+ - spec/spec_helper.rb
95
+ - spec/support/data.rb
96
+ - spec/support/models.rb
97
+ - spec/support/schema.rb