client_side_validations-mongo_mapper 0.10.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/client_side_validations/mongo_mapper/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Brian Cardarella"]
6
+ gem.email = ["bcardarella@gmail.com"]
7
+ gem.description = %q{MongoMapper Plugin for ClientSideValidaitons}
8
+ gem.summary = %q{MongoMapper Plugin for ClientSideValidations}
9
+ gem.homepage = 'https://github.com/dockyard/client_side_validations-mongo_mapper'
10
+
11
+ gem.files = `git ls-files -- {lib/*,vendor/*,*.gemspec}`.split("\n")
12
+ gem.name = 'client_side_validations-mongo_mapper'
13
+ gem.require_paths = ['lib']
14
+ gem.version = ClientSideValidations::MongoMapper::VERSION
15
+
16
+ gem.add_dependency 'client_side_validations', '~> 3.2.0.beta.1'
17
+ gem.add_dependency 'mongo_mapper', '~> 0.10.1'
18
+
19
+ gem.add_development_dependency 'bson_ext'
20
+ gem.add_development_dependency 'rails', '~> 3.2.0'
21
+ gem.add_development_dependency 'mocha'
22
+
23
+ # For QUnit testing
24
+ gem.add_development_dependency 'sinatra', '~> 1.0'
25
+ gem.add_development_dependency 'shotgun'
26
+ gem.add_development_dependency 'thin'
27
+ gem.add_development_dependency 'json'
28
+ end
@@ -0,0 +1,24 @@
1
+ module ClientSideValidations::MongoMapper
2
+ class Middleware
3
+
4
+ def self.is_class?(klass)
5
+ klass < ::MongoMapper::Document
6
+ end
7
+
8
+ # Still need to handle embedded documents
9
+ def self.is_unique?(klass, attribute, value, params)
10
+ if params[:case_sensitive] == 'false'
11
+ value = Regexp.new("^#{Regexp.escape(value.to_s)}$", Regexp::IGNORECASE)
12
+ end
13
+
14
+ criteria = klass.where(attribute => value)
15
+ criteria = criteria.where(:_id => {'$ne' => BSON::ObjectId(params[:id])}) if params[:id]
16
+
17
+ (params[:scope] || {}).each do |key, value|
18
+ criteria = criteria.where(key => value)
19
+ end
20
+
21
+ !criteria.exists?
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,28 @@
1
+ module ClientSideValidations::MongoMapper
2
+ module Uniqueness
3
+ def client_side_hash(model, attribute)
4
+ hash = {}
5
+ hash[:message] = model.errors.generate_message(attribute, message_type, options.except(:scope))
6
+ hash[:case_sensitive] = options[:case_sensitive] if options.key?(:case_sensitive)
7
+ hash[:id] = model.id unless model.new_record?
8
+ if options.key?(:scope) && options[:scope].present?
9
+ hash[:scope] = Array.wrap(options[:scope]).inject({}) do |scope_hash, scope_item|
10
+ scope_hash.merge!(scope_item => model.send(scope_item))
11
+ end
12
+ end
13
+
14
+ unless model.class.name.demodulize == model.class.name
15
+ hash[:class] = model.class.name.underscore
16
+ end
17
+
18
+ hash
19
+ end
20
+
21
+ private
22
+
23
+ def message_type
24
+ :taken
25
+ end
26
+ end
27
+ end
28
+
@@ -0,0 +1,5 @@
1
+ module ClientSideValidations
2
+ module MongoMapper
3
+ VERSION = '0.10.0.beta.1'
4
+ end
5
+ end
@@ -0,0 +1,12 @@
1
+ require 'client_side_validations/active_model'
2
+ require 'client_side_validations/middleware'
3
+ require 'client_side_validations/mongo_mapper/middleware'
4
+
5
+ %w{uniqueness}.each do |validator|
6
+ require "client_side_validations/mongo_mapper/#{validator}"
7
+ validator.capitalize!
8
+ eval "MongoMapper::Plugins::Validations::#{validator}Validator.send(:include, ClientSideValidations::MongoMapper::#{validator})"
9
+ end
10
+
11
+ # ActiveRecord::Base.send(:include, ClientSideValidations::ActiveModel::Validations)
12
+ ClientSideValidations::Middleware::Uniqueness.register_orm(ClientSideValidations::MongoMapper::Middleware)
@@ -0,0 +1 @@
1
+ require 'client_side_validations/mongo_mapper'
metadata ADDED
@@ -0,0 +1,150 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: client_side_validations-mongo_mapper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.10.0.beta.1
5
+ prerelease: 7
6
+ platform: ruby
7
+ authors:
8
+ - Brian Cardarella
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-22 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: client_side_validations
16
+ requirement: &70151538078580 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 3.2.0.beta.1
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70151538078580
25
+ - !ruby/object:Gem::Dependency
26
+ name: mongo_mapper
27
+ requirement: &70151538072760 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 0.10.1
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70151538072760
36
+ - !ruby/object:Gem::Dependency
37
+ name: bson_ext
38
+ requirement: &70151538070920 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70151538070920
47
+ - !ruby/object:Gem::Dependency
48
+ name: rails
49
+ requirement: &70151538068420 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 3.2.0
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70151538068420
58
+ - !ruby/object:Gem::Dependency
59
+ name: mocha
60
+ requirement: &70151538066340 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70151538066340
69
+ - !ruby/object:Gem::Dependency
70
+ name: sinatra
71
+ requirement: &70151538061460 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ version: '1.0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *70151538061460
80
+ - !ruby/object:Gem::Dependency
81
+ name: shotgun
82
+ requirement: &70151538057880 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *70151538057880
91
+ - !ruby/object:Gem::Dependency
92
+ name: thin
93
+ requirement: &70151538054460 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ type: :development
100
+ prerelease: false
101
+ version_requirements: *70151538054460
102
+ - !ruby/object:Gem::Dependency
103
+ name: json
104
+ requirement: &70151538050920 !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: *70151538050920
113
+ description: MongoMapper Plugin for ClientSideValidaitons
114
+ email:
115
+ - bcardarella@gmail.com
116
+ executables: []
117
+ extensions: []
118
+ extra_rdoc_files: []
119
+ files:
120
+ - client_side_validations-simple_form.gemspec
121
+ - lib/client_side_validations-mongo_mapper.rb
122
+ - lib/client_side_validations/mongo_mapper.rb
123
+ - lib/client_side_validations/mongo_mapper/middleware.rb
124
+ - lib/client_side_validations/mongo_mapper/uniqueness.rb
125
+ - lib/client_side_validations/mongo_mapper/version.rb
126
+ homepage: https://github.com/dockyard/client_side_validations-mongo_mapper
127
+ licenses: []
128
+ post_install_message:
129
+ rdoc_options: []
130
+ require_paths:
131
+ - lib
132
+ required_ruby_version: !ruby/object:Gem::Requirement
133
+ none: false
134
+ requirements:
135
+ - - ! '>='
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ required_rubygems_version: !ruby/object:Gem::Requirement
139
+ none: false
140
+ requirements:
141
+ - - ! '>'
142
+ - !ruby/object:Gem::Version
143
+ version: 1.3.1
144
+ requirements: []
145
+ rubyforge_project:
146
+ rubygems_version: 1.8.10
147
+ signing_key:
148
+ specification_version: 3
149
+ summary: MongoMapper Plugin for ClientSideValidations
150
+ test_files: []