vorm 0.0.2.alpha

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0226887b2444ffaa689f04548cdfc5365cfe4189
4
+ data.tar.gz: 6a8989a13c330ba6c213cfba69197b61127128da
5
+ SHA512:
6
+ metadata.gz: 940b8ba11cc2b72732127c375e4ce761c830a8d96e053aa396e84c9e39d36fb5ad1ffc68428ea1f22aaadaca1e3ae8c00754726ae922916831789ebc53a97417
7
+ data.tar.gz: 1cd848b8b1b8dfc82706dc3d303ac0698309496a06e29368ef65c298fdb4d0943415b1ce278d84cd23569c83777013d404b0c18b9f51fbf84c0b77fadd766ec2
data/.gitignore ADDED
@@ -0,0 +1,25 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+
24
+ *.swp
25
+
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.1
4
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Juho H.
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.
data/README.md ADDED
@@ -0,0 +1,62 @@
1
+ # Vorm
2
+
3
+ Simple ORM for Ruby.
4
+
5
+ **This is a rewrite, and still under development.**
6
+
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ gem 'vorm'
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install vorm
21
+
22
+
23
+ ## Usage
24
+
25
+ Inherit from `Vorm::Model` to get the goodies.
26
+
27
+ ```ruby
28
+ class User < Vorm::Model
29
+ # table name
30
+ table 'users'
31
+
32
+ # field names
33
+ field 'email'
34
+ field 'phonenumber'
35
+
36
+ # validators
37
+ validate 'email' do |email|
38
+ # field will be passed to block
39
+ # if it isn't empty, so here !email.nil?
40
+ "Email not valid" if email !~ /@/
41
+ end
42
+
43
+ # callbacks
44
+ def self.create!(*args)
45
+ parent_said = super(args)
46
+ # send email, or whateva
47
+ SignUpMailer.send_welcome(parent_said.id)
48
+ # return what my mama said
49
+ parent_said
50
+ end
51
+ end
52
+ ```
53
+
54
+
55
+ ## Contributing
56
+
57
+ 1. Fork it ( https://github.com/vastus/vorm/fork )
58
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
59
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
60
+ 4. Push to the branch (`git push origin my-new-feature`)
61
+ 5. Create a new Pull Request
62
+
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+
data/lib/vorm/model.rb ADDED
@@ -0,0 +1,8 @@
1
+ require 'set'
2
+
3
+ module Vorm
4
+ class Model
5
+ include Persistable
6
+ end
7
+ end
8
+
@@ -0,0 +1,24 @@
1
+ module Vorm
2
+ module Persistable
3
+ def self.included(base)
4
+ base.extend(ClassMethods)
5
+ end
6
+
7
+ module ClassMethods
8
+ def table(name = nil)
9
+ raise(ArgumentError, "Table name must be a string") if name && !name.is_a?(String)
10
+ @table ||= name
11
+ end
12
+
13
+ def field(name)
14
+ raise(ArgumentError, "Field name must be a string") if name && !name.is_a?(String)
15
+ @fields ? @fields.add(name) : @fields = Set.new([name])
16
+ end
17
+
18
+ def fields
19
+ @fields
20
+ end
21
+ end
22
+ end
23
+ end
24
+
@@ -0,0 +1,4 @@
1
+ module Vorm
2
+ VERSION = "0.0.2.alpha"
3
+ end
4
+
data/lib/vorm.rb ADDED
@@ -0,0 +1,7 @@
1
+ require 'vorm/version'
2
+ require 'vorm/persistable'
3
+ require 'vorm/model'
4
+
5
+ module Vorm
6
+ end
7
+
@@ -0,0 +1,82 @@
1
+ module Vorm
2
+ class Model
3
+ def self.reset
4
+ @table = nil
5
+ @fields = nil
6
+ end
7
+ end
8
+ end
9
+
10
+ describe Vorm::Model do
11
+ context "class methods" do
12
+ subject { Vorm::Model }
13
+
14
+ describe ".table" do
15
+ before { subject.reset }
16
+
17
+ it { is_expected.to respond_to(:table) }
18
+
19
+ it "raises when name is not string" do
20
+ expect { subject.table(:users) }
21
+ .to raise_error(ArgumentError, "Table name must be a string")
22
+ end
23
+
24
+ it "sets the table correctly" do
25
+ expect { subject.table('users') }
26
+ .to change(subject, :table).to('users')
27
+ end
28
+
29
+ it "gets the table" do
30
+ subject.table('users')
31
+ expect(subject.table).to eq('users')
32
+ end
33
+
34
+ it "setting the table again does not change it (cached)" do
35
+ subject.table('users')
36
+ expect { subject.table('another table') }
37
+ .not_to change(subject, :table)
38
+ end
39
+ end
40
+
41
+ describe ".field" do
42
+ before { subject.reset }
43
+
44
+ it { is_expected.to respond_to(:field) }
45
+
46
+ it "raises when name is not string" do
47
+ expect { subject.field(:email) }
48
+ .to raise_error(ArgumentError, "Field name must be a string")
49
+ end
50
+
51
+ it "sets the field correctly" do
52
+ expect { subject.field('email') }
53
+ .to change(subject, :fields)
54
+ end
55
+
56
+
57
+ it "ignores duplicates" do
58
+ subject.field('email')
59
+ subject.field('email')
60
+ expect(subject.fields).to eq(Set.new(['email']))
61
+ end
62
+ end
63
+
64
+ describe ".fields" do
65
+ before { subject.reset }
66
+
67
+ it { is_expected.to respond_to(:fields) }
68
+
69
+ it "gets fields when only one set" do
70
+ subject.field('email')
71
+ expect(subject.fields).to eq(Set.new(['email']))
72
+ end
73
+
74
+ it "gets the fields when multiple set" do
75
+ subject.field('email')
76
+ subject.field('dob')
77
+ expect(subject.fields).to eq(Set.new(['email', 'dob']))
78
+ end
79
+ end
80
+ end
81
+ end
82
+
@@ -0,0 +1,93 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
4
+ # file to always be loaded, without a need to explicitly require it in any files.
5
+ #
6
+ # Given that it is always loaded, you are encouraged to keep this file as
7
+ # light-weight as possible. Requiring heavyweight dependencies from this file
8
+ # will add to the boot time of your test suite on EVERY test run, even for an
9
+ # individual file that may not need all of that loaded. Instead, consider making
10
+ # a separate helper file that requires the additional dependencies and performs
11
+ # the additional setup, and require it from the spec files that actually need it.
12
+ #
13
+ # The `.rspec` file also contains a few flags that are not defaults but that
14
+ # users commonly want.
15
+ #
16
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
17
+
18
+ require 'vorm'
19
+
20
+ RSpec.configure do |config|
21
+ # rspec-expectations config goes here. You can use an alternate
22
+ # assertion/expectation library such as wrong or the stdlib/minitest
23
+ # assertions if you prefer.
24
+ config.expect_with :rspec do |expectations|
25
+ # This option will default to `true` in RSpec 4. It makes the `description`
26
+ # and `failure_message` of custom matchers include text for helper methods
27
+ # defined using `chain`, e.g.:
28
+ # be_bigger_than(2).and_smaller_than(4).description
29
+ # # => "be bigger than 2 and smaller than 4"
30
+ # ...rather than:
31
+ # # => "be bigger than 2"
32
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
33
+ end
34
+
35
+ # rspec-mocks config goes here. You can use an alternate test double
36
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
37
+ config.mock_with :rspec do |mocks|
38
+ # Prevents you from mocking or stubbing a method that does not exist on
39
+ # a real object. This is generally recommended, and will default to
40
+ # `true` in RSpec 4.
41
+ mocks.verify_partial_doubles = true
42
+ end
43
+
44
+ # The settings below are suggested to provide a good initial experience
45
+ # with RSpec, but feel free to customize to your heart's content.
46
+ =begin
47
+ # These two settings work together to allow you to limit a spec run
48
+ # to individual examples or groups you care about by tagging them with
49
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
50
+ # get run.
51
+ config.filter_run :focus
52
+ config.run_all_when_everything_filtered = true
53
+
54
+ # Limits the available syntax to the non-monkey patched syntax that is recommended.
55
+ # For more details, see:
56
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
57
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
58
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
59
+ config.disable_monkey_patching!
60
+
61
+ # This setting enables warnings. It's recommended, but in some cases may
62
+ # be too noisy due to issues in dependencies.
63
+ config.warnings = true
64
+
65
+ # Many RSpec users commonly either run the entire suite or an individual
66
+ # file, and it's useful to allow more verbose output when running an
67
+ # individual spec file.
68
+ if config.files_to_run.one?
69
+ # Use the documentation formatter for detailed output,
70
+ # unless a formatter has already been configured
71
+ # (e.g. via a command-line flag).
72
+ config.default_formatter = 'doc'
73
+ end
74
+
75
+ # Print the 10 slowest examples and example groups at the
76
+ # end of the spec run, to help surface which specs are running
77
+ # particularly slow.
78
+ config.profile_examples = 10
79
+
80
+ # Run specs in random order to surface order dependencies. If you find an
81
+ # order dependency and want to debug it, you can fix the order by providing
82
+ # the seed, which is printed after each run.
83
+ # --seed 1234
84
+ config.order = :random
85
+
86
+ # Seed global randomization in this process using the `--seed` CLI option.
87
+ # Setting this allows you to use `--seed` to deterministically reproduce
88
+ # test failures related to randomization by passing the same `--seed` value
89
+ # as the one that triggered the failure.
90
+ Kernel.srand config.seed
91
+ =end
92
+ end
93
+
data/vorm.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'vorm/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "vorm"
8
+ spec.version = Vorm::VERSION
9
+ spec.authors = ["Juho Hautala"]
10
+ spec.email = ["juho.hautala@helsinki.fi"]
11
+ spec.summary = %q{Simple ORM.}
12
+ spec.description = %q{Simple, pluggable (your own db adapter) ORM for those little projects.}
13
+ spec.homepage = "https://github.com/vastus/vorm"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
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_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake", "~> 10.3.2"
23
+ spec.add_development_dependency "rspec", "~> 3.1.7"
24
+ end
25
+
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vorm
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2.alpha
5
+ platform: ruby
6
+ authors:
7
+ - Juho Hautala
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 10.3.2
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 10.3.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 3.1.7
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 3.1.7
55
+ description: Simple, pluggable (your own db adapter) ORM for those little projects.
56
+ email:
57
+ - juho.hautala@helsinki.fi
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - lib/vorm.rb
70
+ - lib/vorm/model.rb
71
+ - lib/vorm/persistable.rb
72
+ - lib/vorm/version.rb
73
+ - spec/lib/vorm/model_spec.rb
74
+ - spec/spec_helper.rb
75
+ - vorm.gemspec
76
+ homepage: https://github.com/vastus/vorm
77
+ licenses:
78
+ - MIT
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">"
92
+ - !ruby/object:Gem::Version
93
+ version: 1.3.1
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.2.2
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: Simple ORM.
100
+ test_files:
101
+ - spec/lib/vorm/model_spec.rb
102
+ - spec/spec_helper.rb
103
+ has_rdoc: