rubyless 0.7.0 → 0.8.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,9 @@
1
+ == 0.8.0 2010-11-15
2
+
3
+ * Major enhancements
4
+ * Better resolution when receiving dynamic classes or proxy.
5
+ * Fixed a bug where anonymous classes would be memoized.
6
+
1
7
  == 0.7.0 2010-09-13
2
8
 
3
9
  * Major enhancements
@@ -1,3 +1,3 @@
1
1
  module RubyLess
2
- VERSION = '0.7.0'
2
+ VERSION = '0.8.0'
3
3
  end
@@ -26,7 +26,7 @@ module RubyLess
26
26
  s
27
27
  end
28
28
  end
29
-
29
+
30
30
  # Find safe method in all ancestry
31
31
  klass.ancestors.each do |ancestor|
32
32
  # FIXME: find a way to optimize this search !
@@ -267,6 +267,7 @@ module RubyLess
267
267
  end
268
268
 
269
269
  def self.safe_method_with_hash_args(klass, signature, hash_args)
270
+
270
271
  if type = safe_methods_for(klass)[signature]
271
272
  unless allowed_args = type[:hash_args]
272
273
  # All arguments allowed
@@ -9,8 +9,17 @@ module RubyLess
9
9
  return type
10
10
  elsif signature.kind_of?(Array)
11
11
  size = signature.size
12
- ancestors = signature.map {|k| k.kind_of?(Class) ? k.ancestors : [k]}
13
-
12
+ static_types = true
13
+ ancestors = signature.map do |k|
14
+ if k.kind_of?(Symbol)
15
+ [k]
16
+ elsif k.kind_of?(Class) && k.name != ''
17
+ k.ancestors
18
+ else
19
+ static_types = false
20
+ k.respond_to?(:ancestors) ? k.ancestors : [k]
21
+ end
22
+ end
14
23
  each do |key, type|
15
24
  next unless key.size == size
16
25
  ok = true
@@ -21,8 +30,8 @@ module RubyLess
21
30
  end
22
31
  end
23
32
  if ok
24
- # insert in cache
25
- self[signature] = type
33
+ # insert in cache if the signature does not contain dynamic types
34
+ self[signature] = type if static_types
26
35
  return type
27
36
  end
28
37
  end
data/rubyless.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rubyless}
8
- s.version = "0.7.0"
8
+ s.version = "0.8.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Gaspard Bucher"]
12
- s.date = %q{2010-09-14}
12
+ s.date = %q{2010-11-15}
13
13
  s.description = %q{RubyLess is an interpreter for "safe ruby". The idea is to transform some "unsafe" ruby code into safe, type checked ruby, eventually rewriting some variables or methods.}
14
14
  s.email = %q{gaspard@teti.ch}
15
15
  s.extra_rdoc_files = [
@@ -56,7 +56,7 @@ Gem::Specification.new do |s|
56
56
  s.homepage = %q{http://zenadmin.org/546}
57
57
  s.rdoc_options = ["--charset=UTF-8"]
58
58
  s.require_paths = ["lib"]
59
- s.rubygems_version = %q{1.3.6}
59
+ s.rubygems_version = %q{1.3.7}
60
60
  s.summary = %q{RubyLess is an interpreter for "safe ruby"}
61
61
  s.test_files = [
62
62
  "test/mock/active_record_mock.rb",
@@ -75,7 +75,7 @@ Gem::Specification.new do |s|
75
75
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
76
76
  s.specification_version = 3
77
77
 
78
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
78
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
79
79
  s.add_runtime_dependency(%q<ruby_parser>, [">= 2.0.4"])
80
80
  s.add_runtime_dependency(%q<sexp_processor>, [">= 3.0.1"])
81
81
  s.add_development_dependency(%q<shoulda>, [">= 0"])
@@ -202,3 +202,7 @@ class:
202
202
  class_map_as_string:
203
203
  src: "@foo.kind_of?(Document)"
204
204
  tem: "node.is_like?(\"DOC\")"
205
+
206
+ proc_to_resolve_class:
207
+ src: "author"
208
+ tem: "node.author"
@@ -74,4 +74,8 @@ call_on_class:
74
74
 
75
75
  unknown_constant:
76
76
  src: "RubyLess"
77
- tem: "Unknown constant 'RubyLess'."
77
+ tem: "Unknown constant 'RubyLess'."
78
+
79
+ ternary_operator:
80
+ src: "@foo ? 'xx' : 15"
81
+ tem: "/Error in conditional expression.*String != Number/"
@@ -65,7 +65,7 @@ class RubyLessTest < Test::Unit::TestCase
65
65
  res ={:class => Number, :prepend_args => RubyLess::TypedString.new('10', :class => Number), :method => 'add'}
66
66
  elsif context && res = context[:node_class].safe_method_type(signature)
67
67
  # try to execute method in the current var "var.method"
68
- res = res.call(self, signature) if res.kind_of?(Proc)
68
+ res = res[:class].call(self, signature) if res[:class].kind_of?(Proc)
69
69
  res = res.merge(:method => "#{context[:node]}.#{res[:method] || signature[0]}")
70
70
  end
71
71
  end
@@ -18,7 +18,9 @@ class Dummy < RubyLess::ActiveRecordMock
18
18
  :foo => :bar,
19
19
  [:width, {:mode => String, :type => String, 'nice' => Boolean}] => String,
20
20
  [:kind_of?, Class] => Boolean,
21
- [:kind_of?, String] => {:method => 'is_like?', :class => Boolean}
21
+ [:kind_of?, String] => {:method => 'is_like?', :class => Boolean},
22
+ :author => (Proc.new do |h, s| {:method => 'author', :class => Dummy} end)
23
+ #:author => {:method => 'author', :class => Dummy}
22
24
 
23
25
  safe_context :spouse => 'Dummy',
24
26
  :husband => {:class => 'Dummy', :context => {:clever => 'no'}}
@@ -81,6 +83,10 @@ class Dummy < RubyLess::ActiveRecordMock
81
83
  def zip
82
84
  10
83
85
  end
86
+
87
+ def author
88
+ Dummy.new('bob')
89
+ end
84
90
  end
85
91
 
86
92
  class SubDummy < Dummy
@@ -40,5 +40,12 @@ class SignatureHashTest < Test::Unit::TestCase
40
40
  assert subject.keys.include?(key)
41
41
  end
42
42
 
43
+ should 'not cache key on anonymous class match' do
44
+ key = [:x, Class.new(String), String]
45
+ assert !subject.keys.include?(key)
46
+ assert_equal 'x_string_string', subject[key]
47
+ assert !subject.keys.include?(key)
48
+ end
49
+
43
50
  end
44
51
  end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubyless
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 63
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
- - 7
8
+ - 8
8
9
  - 0
9
- version: 0.7.0
10
+ version: 0.8.0
10
11
  platform: ruby
11
12
  authors:
12
13
  - Gaspard Bucher
@@ -14,16 +15,18 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-09-14 00:00:00 +02:00
18
+ date: 2010-11-15 00:00:00 +01:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: ruby_parser
22
23
  prerelease: false
23
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
24
26
  requirements:
25
27
  - - ">="
26
28
  - !ruby/object:Gem::Version
29
+ hash: 7
27
30
  segments:
28
31
  - 2
29
32
  - 0
@@ -35,9 +38,11 @@ dependencies:
35
38
  name: sexp_processor
36
39
  prerelease: false
37
40
  requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
38
42
  requirements:
39
43
  - - ">="
40
44
  - !ruby/object:Gem::Version
45
+ hash: 5
41
46
  segments:
42
47
  - 3
43
48
  - 0
@@ -49,9 +54,11 @@ dependencies:
49
54
  name: shoulda
50
55
  prerelease: false
51
56
  requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
52
58
  requirements:
53
59
  - - ">="
54
60
  - !ruby/object:Gem::Version
61
+ hash: 3
55
62
  segments:
56
63
  - 0
57
64
  version: "0"
@@ -61,9 +68,11 @@ dependencies:
61
68
  name: yamltest
62
69
  prerelease: false
63
70
  requirement: &id004 !ruby/object:Gem::Requirement
71
+ none: false
64
72
  requirements:
65
73
  - - ">="
66
74
  - !ruby/object:Gem::Version
75
+ hash: 7
67
76
  segments:
68
77
  - 0
69
78
  - 6
@@ -126,23 +135,27 @@ rdoc_options:
126
135
  require_paths:
127
136
  - lib
128
137
  required_ruby_version: !ruby/object:Gem::Requirement
138
+ none: false
129
139
  requirements:
130
140
  - - ">="
131
141
  - !ruby/object:Gem::Version
142
+ hash: 3
132
143
  segments:
133
144
  - 0
134
145
  version: "0"
135
146
  required_rubygems_version: !ruby/object:Gem::Requirement
147
+ none: false
136
148
  requirements:
137
149
  - - ">="
138
150
  - !ruby/object:Gem::Version
151
+ hash: 3
139
152
  segments:
140
153
  - 0
141
154
  version: "0"
142
155
  requirements: []
143
156
 
144
157
  rubyforge_project:
145
- rubygems_version: 1.3.6
158
+ rubygems_version: 1.3.7
146
159
  signing_key:
147
160
  specification_version: 3
148
161
  summary: RubyLess is an interpreter for "safe ruby"