modelmania 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 +4 -0
- data/Gemfile +7 -0
- data/Rakefile +2 -0
- data/lib/modelmania/active_model_validators.rb +21 -0
- data/lib/modelmania/version.rb +3 -0
- data/lib/modelmania.rb +3 -0
- data/modelmania.gemspec +21 -0
- metadata +63 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'active_model'
|
2
|
+
|
3
|
+
class EmailValidator < ActiveModel::EachValidator
|
4
|
+
def validate_each(record, attribute, value)
|
5
|
+
record.errors[attribute] << (options[:message] || "is not a valid email address") unless
|
6
|
+
value =~ /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class ActiveRecord::Base
|
11
|
+
|
12
|
+
def self.validates_single_record options={}
|
13
|
+
|
14
|
+
proc = Proc.new do
|
15
|
+
n = new_record? ? 0 : 1
|
16
|
+
errors.add :base, options[:message] || "only one #{self.class} can is allow to exist" if (self.class.count != n)
|
17
|
+
end
|
18
|
+
|
19
|
+
validate proc, options
|
20
|
+
end
|
21
|
+
end
|
data/lib/modelmania.rb
ADDED
data/modelmania.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "modelmania/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "modelmania"
|
7
|
+
s.version = Modelmania::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Sam Taylor"]
|
10
|
+
s.email = ["sjltaylor@gmail.com"]
|
11
|
+
s.homepage = "http://sjltaylor.com"
|
12
|
+
s.summary = %q{Rails active model extensions}
|
13
|
+
#s.description = %q{TODO: Write a gem description}
|
14
|
+
|
15
|
+
s.rubyforge_project = "modelmania"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: modelmania
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Sam Taylor
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-04-12 00:00:00 +01:00
|
14
|
+
default_executable:
|
15
|
+
dependencies: []
|
16
|
+
|
17
|
+
description:
|
18
|
+
email:
|
19
|
+
- sjltaylor@gmail.com
|
20
|
+
executables: []
|
21
|
+
|
22
|
+
extensions: []
|
23
|
+
|
24
|
+
extra_rdoc_files: []
|
25
|
+
|
26
|
+
files:
|
27
|
+
- .gitignore
|
28
|
+
- Gemfile
|
29
|
+
- Rakefile
|
30
|
+
- lib/modelmania.rb
|
31
|
+
- lib/modelmania/active_model_validators.rb
|
32
|
+
- lib/modelmania/version.rb
|
33
|
+
- modelmania.gemspec
|
34
|
+
has_rdoc: true
|
35
|
+
homepage: http://sjltaylor.com
|
36
|
+
licenses: []
|
37
|
+
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options: []
|
40
|
+
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: "0"
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: "0"
|
55
|
+
requirements: []
|
56
|
+
|
57
|
+
rubyforge_project: modelmania
|
58
|
+
rubygems_version: 1.5.0
|
59
|
+
signing_key:
|
60
|
+
specification_version: 3
|
61
|
+
summary: Rails active model extensions
|
62
|
+
test_files: []
|
63
|
+
|