mcfly 0.0.3 → 0.0.4

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 CHANGED
@@ -18,4 +18,6 @@ tmp
18
18
  *~
19
19
  *.komodoproject
20
20
  .rvmrc
21
+ .ruby-version
22
+ .ruby-gemset
21
23
  spec/dummy/log
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Mcfly
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
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.3
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-03-27 00:00:00.000000000 Z
12
+ date: 2013-06-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails