classy-inheritance 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,5 @@
1
+ == 0.2.0 2008-06-02
2
+ * Add: When defining a depends_on that is polymorhic the requisite class has two methods added: "is_a_<model>?" and "as_a_<model>".
1
3
  == 0.1.1 2008-05-30
2
4
  * Fix: Merge when other conditionals are passed to the find_with method was incorrectly called without bang!
3
5
  == 0.1.0 2008-05-29
@@ -35,12 +35,33 @@ module Stonean
35
35
  # Adds a find_with_<model_sym> class method
36
36
  define_find_with_method(model_sym)
37
37
 
38
+ if options[:as]
39
+ define_can_be_method_on_requisite_class(model_sym, options[:as])
40
+ end
38
41
 
39
42
  options[:attrs].each{|attr| define_accessors(model_sym, attr)}
40
43
  end
41
44
 
42
- #model_instance = instance_variable_get("@#{model_sym}")
43
45
  private
46
+
47
+ def can_be(model_sym, options = {})
48
+ unless options[:as]
49
+ raise ArgumentError, ":as attribute required when calling can_be"
50
+ end
51
+
52
+ klass = model_sym.to_s.classify
53
+
54
+ define_method "is_a_#{model_sym}?" do
55
+ eval("self.#{options[:as]}_type == '#{klass}'")
56
+ end
57
+
58
+ find_with_method = "find_with_#{self.name.underscore}"
59
+
60
+ define_method "as_a_#{model_sym}" do
61
+ eval("#{klass}.send(:#{find_with_method},self.#{options[:as]}_id)")
62
+ end
63
+ end
64
+
44
65
  def define_relationship(model_sym, options)
45
66
  if options[:as]
46
67
  has_one model_sym, polymorphic_constraints(options[:as])
@@ -98,6 +119,13 @@ module Stonean
98
119
  end
99
120
  end
100
121
 
122
+ def define_can_be_method_on_requisite_class(model_sym, polymorphic_name)
123
+ klass = model_sym.to_s.classify
124
+ requisite_klass = eval(klass)
125
+ requisite_klass.send :can_be, self.name.underscore,
126
+ :as => polymorphic_name
127
+ end
128
+
101
129
  def polymorphic_constraints(polymorphic_name)
102
130
  { :foreign_key => "#{polymorphic_name}_id",
103
131
  :conditions => "#{polymorphic_name}_type = '#{self.name}'"}
@@ -1,8 +1,8 @@
1
1
  module ClassyInheritance #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
- MINOR = 1
5
- TINY = 1
4
+ MINOR = 2
5
+ TINY = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/website/index.html CHANGED
@@ -33,11 +33,21 @@
33
33
  <h1>Classy Inheritance</h1>
34
34
  <div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/classyinherit"; return false'>
35
35
  <p>Get Version</p>
36
- <a href="http://rubyforge.org/projects/classyinherit" class="numbers">0.1.1</a>
36
+ <a href="http://rubyforge.org/projects/classyinherit" class="numbers">0.2.0</a>
37
37
  </div>
38
38
  <p><i>&#8220;You stay classy, inheritance&#8221; &#8211; Gibson</i></p>
39
39
 
40
40
 
41
+ <h2>Consolidation of information</h2>
42
+
43
+
44
+ <p>Maintaining this page, the wiki at GitHub, the Google Group and no issue tracker is not an ideal setup. So, everything is moving to <a href="http://stonean.com">stonean.com</a> where I&#8217;m giving <a href="http://redmine.org">Redmine</a> a shot a running everything for me. I&#8217;ll be posting release announcements to the news feed for each project and keeping the docs up-to-date. Hopefully this will be better for everyone.</p>
45
+
46
+
47
+ <p>Thanks for your interest in Classy Inheritance,<br/>
48
+ -andy</p>
49
+
50
+
41
51
  <h2>What</h2>
42
52
 
43
53
 
@@ -111,7 +121,7 @@ require "classy-inheritance"
111
121
 
112
122
  <p>This code is free to use under the terms of the <span class="caps">MIT</span> license.</p>
113
123
  <p class="coda">
114
- <a href="http://blog.stonean.com">Andrew Stone</a>, 29th May 2008<br>
124
+ <a href="http://blog.stonean.com">Andrew Stone</a>, 2nd June 2008<br>
115
125
  Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
116
126
  </p>
117
127
  </div>
data/website/index.txt CHANGED
@@ -2,6 +2,14 @@ h1. <a href="http://lockdown.rubyforge.org">Classy Inheritance</a>
2
2
 
3
3
  <i>"You stay classy, inheritance" - Gibson</i>
4
4
 
5
+ h2. Consolidation of information
6
+
7
+ Maintaining this page, the wiki at GitHub, the Google Group and no issue tracker is not an ideal setup. So, everything is moving to "stonean.com":http://stonean.com where I'm giving "Redmine":http://redmine.org a shot a running everything for me. I'll be posting release announcements to the news feed for each project and keeping the docs up-to-date. Hopefully this will be better for everyone.
8
+
9
+ Thanks for your interest in Classy Inheritance,<br/>
10
+ -andy
11
+
12
+
5
13
  h2. What
6
14
 
7
15
  For now, Classy Inheritance adds a depends_on class method to your ActiveRecord model so that you can define requisite objects.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: classy-inheritance
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Stone
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-05-30 00:00:00 -04:00
12
+ date: 2008-06-03 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies: []
15
15