mcfly 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/lib/mcfly/has_mcfly.rb +22 -0
- data/lib/mcfly/version.rb +1 -1
- metadata +2 -2
data/.gitignore
CHANGED
data/lib/mcfly/has_mcfly.rb
CHANGED
@@ -3,6 +3,22 @@ require 'delorean_lang'
|
|
3
3
|
module McFly
|
4
4
|
module Model
|
5
5
|
|
6
|
+
class AssociationValidator < ActiveModel::Validator
|
7
|
+
VALSET = Set[nil, Float::INFINITY, 'infinity']
|
8
|
+
|
9
|
+
def validate(entry)
|
10
|
+
raise "need field option" unless options[:field]
|
11
|
+
field = options[:field].to_sym
|
12
|
+
value = entry.send(field)
|
13
|
+
|
14
|
+
return if value.nil?
|
15
|
+
|
16
|
+
unless VALSET.member?(value.obsoleted_dt)
|
17
|
+
entry.errors[field] = "Obsoleted association value!"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
6
22
|
def self.included(base)
|
7
23
|
base.send :extend, ClassMethods
|
8
24
|
end
|
@@ -53,6 +69,12 @@ module McFly
|
|
53
69
|
|
54
70
|
validates_uniqueness_of(*attr_names)
|
55
71
|
end
|
72
|
+
|
73
|
+
def mcfly_belongs_to(name, options = {})
|
74
|
+
validates_with McFly::Model::AssociationValidator, field: name
|
75
|
+
belongs_to(name, options)
|
76
|
+
end
|
77
|
+
|
56
78
|
end
|
57
79
|
|
58
80
|
module InstanceMethods
|
data/lib/mcfly/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mcfly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-06-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|