active_presenters 1.1.4 → 1.1.6

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/lib/proxy.rb CHANGED
@@ -1,13 +1,50 @@
1
1
  module ActivePresenter
2
- class Proxy
3
-
4
- def initialize(options = {}, &block)
5
- if options.is_a? Hash
6
- unless options.empty?
7
- options.each_pair {|k,v| self.send("#{k}=", v)}
2
+
3
+ module Proxy
4
+
5
+ def self.new(options = {}, is_a_list = [])
6
+ # this make each instance uniqiue. that measns that methods will only get defined for that instance of the proxy only.
7
+ # the additional 'Ap' prefix is because String.randomize can sometimes start with a number which isn't valid for the first
8
+ # character of a ruby class name.
9
+ klass_name = "ActivePresenter::Proxy::Ap#{String.randomize.downcase}"
10
+ eval %{
11
+ class #{klass_name}
12
+ include ActivePresenter::ProxyMethods
8
13
  end
14
+ }
15
+ proxy = klass_name.constantize.new(options, is_a_list)
16
+ yield proxy if block_given?
17
+ proxy
18
+ end # new
19
+
20
+ end # Proxy
21
+
22
+ module ProxyMethods
23
+ require 'ostruct'
24
+ def initialize(options = {}, is_a_list = [])
25
+ if !options.nil? && options.is_a?(Hash)
26
+ options.each_pair {|k,v| self.send("#{k}=", v)}
9
27
  end
10
- yield self if block_given?
28
+ @is_a_list = [ActivePresenter::Proxy]
29
+ self.add_is_a(is_a_list)
30
+ end
31
+
32
+ def create_method(name, &block)
33
+ self.class.send(:define_method, name, &block)
34
+ end
35
+
36
+ def is_a?(x)
37
+ test_is_a?(x) ? true : super(x)
38
+ end
39
+
40
+ def kind_of?(x)
41
+ test_is_a?(x) ? true : super(x)
42
+ end
43
+
44
+ def add_is_a(x)
45
+ @is_a_list << x
46
+ @is_a_list.flatten!
47
+ @is_a_list.uniq!
11
48
  end
12
49
 
13
50
  def method_missing(sym, *args)
@@ -24,10 +61,6 @@ module ActivePresenter
24
61
 
25
62
  end
26
63
 
27
- def create_method(name, &block)
28
- self.class.send(:define_method, name, &block)
29
- end
30
-
31
64
  private
32
65
  def gen_methods(key)
33
66
  eval %{
@@ -48,5 +81,9 @@ module ActivePresenter
48
81
  }
49
82
  end
50
83
 
51
- end
52
- end
84
+ def test_is_a?(x)
85
+ return @is_a_list.include?(x)
86
+ end
87
+ end # ProxyMethods
88
+
89
+ end # ActivePresenter
@@ -2,4 +2,4 @@
2
2
  gem_name: active_presenters
3
3
  package: active_presenters
4
4
  project: magrathea
5
- version: 1.1.4
5
+ version: 1.1.6
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
3
3
  specification_version: 1
4
4
  name: active_presenters
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.1.4
7
- date: 2007-11-12 00:00:00 -05:00
6
+ version: 1.1.6
7
+ date: 2007-12-03 00:00:00 -05:00
8
8
  summary: active_presenters
9
9
  require_paths:
10
10
  - lib