sequel_couchbase_model 0.0.1

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: a5216794d8c9ea3493cc71f980818b527315b9d8
4
+ data.tar.gz: a12dd7bc07ebfcff484b4b4a1c6a3589f54f9b06
5
+ SHA512:
6
+ metadata.gz: 8ed2ad81a618dc74897c18c18fba048660251b279887184861425b2a5f45fa1f3a50f11c8bf64e21d8face14080e54d10b896ac8e5dc3bee103f56afb244b777
7
+ data.tar.gz: 3efeba0c9db10f619c93e0beae9c0e183181cf4cddef4646921a6be7a2a2544341b49d16ab000de5dea5607ae7389bb914682638cb008ecafae90cee2d8628ae
data/.gitignore ADDED
@@ -0,0 +1,17 @@
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
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sequel_couchbase_model.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Misha Conway
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,29 @@
1
+ # SequelCouchbaseModel
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'sequel_couchbase_model'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install sequel_couchbase_model
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
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,161 @@
1
+ require "sequel_couchbase_model/version"
2
+
3
+ module Sequel
4
+ module Couchbase
5
+ class ValidationException < RuntimeError
6
+ attr_reader :validation_errors
7
+
8
+ def initialize validation_errors
9
+ @validation_errors = validation_errors
10
+ end
11
+ end
12
+
13
+ class Model < ::Couchbase::Model
14
+ @@plugins = []
15
+
16
+ def self.plugin(plugin, *args, &block)
17
+ m = plugin.is_a?(Module) ? plugin : plugin_module(plugin)
18
+ unless @@plugins.include?(m)
19
+ @@plugins << m
20
+ m.apply(self, *args, &block) if m.respond_to?(:apply)
21
+ include(m::InstanceMethods) if plugin_module_defined?(m, :InstanceMethods)
22
+ extend(m::ClassMethods) if plugin_module_defined?(m, :ClassMethods)
23
+ dataset_extend(m::DatasetMethods) if plugin_module_defined?(m, :DatasetMethods)
24
+ end
25
+ m.configure(self, *args, &block) if m.respond_to?(:configure)
26
+ end
27
+
28
+ def self.plugin_module_defined?(plugin, submod)
29
+ if RUBY_VERSION >= '1.9'
30
+ plugin.const_defined?(submod, false)
31
+ else
32
+ # :nocov:
33
+ plugin.const_defined?(submod)
34
+ # :nocov:
35
+ end
36
+ end
37
+
38
+ def self.plugin_module(plugin)
39
+ module_name = plugin.to_s.gsub(/(^|_)(.)/) { |x| x[-1..-1].upcase }
40
+ if !Sequel::Plugins.const_defined?(module_name) ||
41
+ (Sequel.const_defined?(module_name) &&
42
+ Sequel::Plugins.const_get(module_name) == Sequel.const_get(module_name))
43
+ begin
44
+ Sequel.tsk_require "sequel/plugins/#{plugin}"
45
+ rescue LoadError => e
46
+ begin
47
+ Sequel.tsk_require "sequel_#{plugin}"
48
+ rescue LoadError => e2
49
+ e.message << "; #{e2.message}"
50
+ raise e
51
+ end
52
+ end
53
+ end
54
+ Sequel::Plugins.const_get(module_name)
55
+ end
56
+
57
+ def self.blank_object?(obj)
58
+ return obj.blank? if obj.respond_to?(:blank?)
59
+ case obj
60
+ when NilClass, FalseClass
61
+ true
62
+ when Numeric, TrueClass
63
+ false
64
+ when String
65
+ obj.strip.empty?
66
+ else
67
+ obj.respond_to?(:empty?) ? obj.empty? : false
68
+ end
69
+ end
70
+
71
+ def blank_object?
72
+ self.class.blank_object? self
73
+ end
74
+
75
+ def self.db
76
+ self
77
+ end
78
+
79
+ def self.find! id
80
+ super id
81
+ end
82
+
83
+ def self.find id
84
+ begin
85
+ super id
86
+ rescue Couchbase::Error::NotFound
87
+ nil
88
+ end
89
+ end
90
+
91
+ def valid?
92
+ errors.blank?
93
+ end
94
+
95
+ def save options = {}
96
+ save_ex options, ->(options) { super options }, ->() { false }
97
+ end
98
+
99
+ def save! options = {}
100
+ save_ex options, ->(options) { super options }, ->() {
101
+ raise ValidationException.new(@errors), "Could not save #{self.class.name} model due to failing validation: #{errors.inspect}\n\tmodel was: #{inspect}"
102
+ }
103
+ end
104
+
105
+ def disable_update_timestamps!
106
+ @auto_timestamps_disabled = true
107
+ end
108
+
109
+ def errors
110
+ @errors ||= Sequel::Model::Errors.new
111
+ end
112
+
113
+ protected
114
+ def before_save
115
+ end
116
+
117
+ def after_save
118
+ end
119
+
120
+ def before_validate
121
+ end
122
+
123
+ def validate
124
+ true
125
+ end
126
+
127
+ private
128
+ def save_ex options={}, on_save, on_failure
129
+ errors.clear
130
+ update_timestamps!
131
+ before_validate
132
+ validate
133
+
134
+ if valid?
135
+ before_save
136
+ on_save.call options
137
+ after_save
138
+ true
139
+ else
140
+ on_failure.call
141
+ end
142
+ end
143
+
144
+
145
+ def update_timestamps!
146
+ unless @auto_timestamps_disabled
147
+ begin
148
+ self.created_at ||= Time.now.to_i #doing if attributes.include? :created_at doesn't seem to always work
149
+ rescue NoMethodError
150
+ end
151
+
152
+ begin
153
+ self.updated_at = Time.now.to_i #doing if attributes.include? :updated_at doesn't seem to always work
154
+ rescue NoMethodError
155
+ end
156
+ end
157
+ end
158
+ end
159
+
160
+ end
161
+ end
@@ -0,0 +1,3 @@
1
+ module SequelCouchbaseModel
2
+ VERSION = "0.0.1"
3
+ end
@@ -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 'sequel_couchbase_model/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sequel_couchbase_model"
8
+ spec.version = SequelCouchbaseModel::VERSION
9
+ spec.authors = ["Misha Conway"]
10
+ spec.email = ["misha.conway@machinima.com"]
11
+ spec.description = %q{Integrates sequel validations and sequel hooks into couchbase model.}
12
+ spec.summary = %q{ntegrates sequel validations and sequel hooks into couchbase model.}
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_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency 'sequel'
24
+ spec.add_development_dependency 'couchbase-model'
25
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sequel_couchbase_model
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Misha Conway
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-09 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.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: sequel
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: couchbase-model
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
+ description: Integrates sequel validations and sequel hooks into couchbase model.
70
+ email:
71
+ - misha.conway@machinima.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - lib/sequel_couchbase_model.rb
82
+ - lib/sequel_couchbase_model/version.rb
83
+ - sequel_couchbase_model.gemspec
84
+ homepage: ''
85
+ licenses:
86
+ - MIT
87
+ metadata: {}
88
+ post_install_message:
89
+ rdoc_options: []
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ requirements: []
103
+ rubyforge_project:
104
+ rubygems_version: 2.0.3
105
+ signing_key:
106
+ specification_version: 4
107
+ summary: ntegrates sequel validations and sequel hooks into couchbase model.
108
+ test_files: []