humble 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 99f0c16e389f39eb60cb925e39012f71442a64ca
4
+ data.tar.gz: accf8b6c54011457d43049538d2e6e7561e01653
5
+ SHA512:
6
+ metadata.gz: a28bf2917c0d81a692bc0dd4176d014edc0830a865e35500598ef764cfc80973f9fc342f7585ad18e562831749efb65b3ee2ae341c73b6943dc496586b34fdf3
7
+ data.tar.gz: d06d48f09db1d22f6c61e25541e4e69051fafe5cc09e080c4a39456318fa6e1b4130a4f282c8be5721d0002507318da8294423eede07c8faa5eac56b86239c3a
@@ -0,0 +1,18 @@
1
+ *.db
2
+ *.gem
3
+ *.rbc
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
@@ -0,0 +1 @@
1
+ orm
@@ -0,0 +1 @@
1
+ ruby-2.0.0-p195
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "https://rubygems.org"
2
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 mo khan
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Humble
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'humble'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install humble
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'humble/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "humble"
8
+ spec.version = Humble::VERSION
9
+ spec.authors = ["mo khan"]
10
+ spec.email = ["mo@mokhan.ca"]
11
+ spec.description = %q{a simple ruby orm.}
12
+ spec.summary = %q{an nhibernate like orm for ruby.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "sequel"
22
+ spec.add_development_dependency "bundler", "~> 1.3"
23
+ spec.add_development_dependency "rake"
24
+ spec.add_development_dependency 'rspec'
25
+ spec.add_development_dependency 'rspec-fakes'
26
+ spec.add_development_dependency 'sequel'
27
+ spec.add_development_dependency 'sqlite3'
28
+ end
@@ -0,0 +1,8 @@
1
+ require "humble/version"
2
+ require "humble/session_factory"
3
+ require "humble/session"
4
+ require "humble/configuration"
5
+
6
+ module Humble
7
+
8
+ end
@@ -0,0 +1,24 @@
1
+ module Humble
2
+ class Configuration
3
+ attr_reader :connection_string
4
+
5
+ def initialize(connection_string)
6
+ @mappings = []
7
+ @connection_string = connection_string
8
+ end
9
+
10
+ def add(mapping)
11
+ @mappings.push(mapping)
12
+ end
13
+
14
+ def build_session_factory
15
+ SessionFactory.new(self)
16
+ end
17
+
18
+ def mapping_for(item)
19
+ @mappings.find do |mapping|
20
+ mapping.is_for?(item)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,34 @@
1
+ module Humble
2
+ class Session
3
+ def initialize(connection_factory, mapper_registry)
4
+ @connection_factory = connection_factory
5
+ @mapper_registry = mapper_registry
6
+ end
7
+
8
+ def begin_transaction(&block)
9
+ create_connection.transaction do
10
+ block.call(self)
11
+ end
12
+ end
13
+
14
+ def save(item)
15
+ mapping_for(item).save_using(create_connection, item)
16
+ end
17
+
18
+ def find_all(clazz)
19
+ mapping_for(clazz).find_all_using(create_connection, clazz)
20
+ end
21
+
22
+ private
23
+
24
+ attr_reader :connection_factory, :mapper_registry
25
+
26
+ def create_connection
27
+ @connection ||= connection_factory.create_connection
28
+ end
29
+
30
+ def mapping_for(item)
31
+ mapper_registry.mapping_for(item)
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,15 @@
1
+ module Humble
2
+ class SessionFactory
3
+ def initialize(configuration)
4
+ @configuration = configuration
5
+ end
6
+
7
+ def create_session
8
+ Session.new(self, @configuration)
9
+ end
10
+
11
+ def create_connection
12
+ Sequel.connect(@configuration.connection_string)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ module Humble
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,43 @@
1
+ require "spec_helper"
2
+ require_relative 'fixtures/movie_mapping.rb'
3
+
4
+ describe "orm" do
5
+ let(:connection) { Sequel.connect(connection_string) }
6
+ let(:connection_string) { 'sqlite://test.db' }
7
+ let(:configuration) { Humble::Configuration.new(connection_string) }
8
+ let(:session_factory) { configuration.build_session_factory }
9
+ let(:session) { session_factory.create_session }
10
+
11
+ before :each do
12
+ connection.create_table :movies do
13
+ primary_key :id
14
+ String :name
15
+ end
16
+
17
+ configuration.add(MovieMapping.new)
18
+ session.begin_transaction do |session|
19
+ session.save(Movie.new(:name => 'monsters inc'))
20
+ end
21
+ end
22
+
23
+ after :each do
24
+ connection.drop_table :movies
25
+ end
26
+
27
+ context "when fetching all items" do
28
+ let(:results) { session.find_all Movie }
29
+
30
+ it "should return the correct number of movies" do
31
+ results.count.should == 1
32
+ end
33
+
34
+ it "should return each movie with its name" do
35
+ results.first.name.should == 'monsters inc'
36
+ end
37
+
38
+ it "should return instances of the target type" do
39
+ results.first.should be_instance_of(Movie)
40
+ end
41
+ end
42
+
43
+ end
@@ -0,0 +1,28 @@
1
+ class Movie
2
+ attr_reader :name
3
+
4
+ def initialize(attributes)
5
+ @name = attributes[:name]
6
+ end
7
+ end
8
+
9
+ class MovieMapping
10
+ def is_for?(item)
11
+ item == Movie || item.is_a?(Movie)
12
+ end
13
+
14
+ def save_using(connection, item)
15
+ connection[:movies].insert(:name => item.name)
16
+ end
17
+
18
+ def find_all_using(connection, clazz)
19
+ connection[:movies].map do |row|
20
+ Movie.new(row)
21
+ end
22
+ end
23
+
24
+ def run(map)
25
+ map.table :movies
26
+ end
27
+ end
28
+
@@ -0,0 +1,4 @@
1
+ require "rubygems"
2
+ require 'sequel'
3
+ require "sqlite3"
4
+ require 'humble'
metadata ADDED
@@ -0,0 +1,162 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: humble
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - mo khan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-05-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sequel
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec-fakes
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: sequel
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: sqlite3
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: a simple ruby orm.
112
+ email:
113
+ - mo@mokhan.ca
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - .gitignore
119
+ - .ruby-gemset
120
+ - .ruby-version
121
+ - Gemfile
122
+ - Gemfile.lock
123
+ - LICENSE.txt
124
+ - README.md
125
+ - Rakefile
126
+ - humble.gemspec
127
+ - lib/humble.rb
128
+ - lib/humble/configuration.rb
129
+ - lib/humble/session.rb
130
+ - lib/humble/session_factory.rb
131
+ - lib/humble/version.rb
132
+ - spec/integration/example_spec.rb
133
+ - spec/integration/fixtures/movie_mapping.rb
134
+ - spec/spec_helper.rb
135
+ homepage: ''
136
+ licenses:
137
+ - MIT
138
+ metadata: {}
139
+ post_install_message:
140
+ rdoc_options: []
141
+ require_paths:
142
+ - lib
143
+ required_ruby_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - '>='
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ required_rubygems_version: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - '>='
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ requirements: []
154
+ rubyforge_project:
155
+ rubygems_version: 2.0.3
156
+ signing_key:
157
+ specification_version: 4
158
+ summary: an nhibernate like orm for ruby.
159
+ test_files:
160
+ - spec/integration/example_spec.rb
161
+ - spec/integration/fixtures/movie_mapping.rb
162
+ - spec/spec_helper.rb