rubyless 0.8.4 → 0.8.5
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +5 -0
- data/README.rdoc +13 -0
- data/lib/ruby_less/info.rb +1 -1
- data/lib/ruby_less/processor.rb +22 -0
- data/rubyless.gemspec +2 -2
- data/test/RubyLess/basic.yml +19 -4
- data/test/RubyLess_test.rb +9 -3
- data/test/typed_string_test.rb +8 -1
- metadata +4 -4
data/History.txt
CHANGED
data/README.rdoc
CHANGED
@@ -65,6 +65,19 @@ You can look at the tests for an idea of how to declare things. If you have more
|
|
65
65
|
|
66
66
|
http://zenadmin.org/community
|
67
67
|
|
68
|
+
== TRICKS:
|
69
|
+
|
70
|
+
If you define your own 'safe_method_type' resolution methods, or you define a method by providing a symbol (method executed to get type), you can use the special :prepend_args and :append_args elements in the type response. You need to provide a TypedString or an array of TypedString and these elements will be inserted in the final method. This can be used to provide default values:
|
71
|
+
|
72
|
+
safe_method_type [:parse_date, String] => :get_parse_date
|
73
|
+
|
74
|
+
def get_parse_date(signature)
|
75
|
+
{:class => Time, :append_args => RubyLess::TypedString.new('visitor.tz', :class => TZInfo::Timezone)}
|
76
|
+
end
|
77
|
+
|
78
|
+
# parse_date('2003-12-01')
|
79
|
+
# ==> parse_date('2003-12-01', visitor.tz)
|
80
|
+
|
68
81
|
== WARNING:
|
69
82
|
|
70
83
|
Changing the safe methods during runtime removes the cache for all classes and
|
data/lib/ruby_less/info.rb
CHANGED
data/lib/ruby_less/processor.rb
CHANGED
@@ -400,6 +400,9 @@ module RubyLess
|
|
400
400
|
|
401
401
|
def args_with_prepend(args, opts)
|
402
402
|
if prepend_args = opts[:prepend_args]
|
403
|
+
if prepend_args.kind_of?(Array)
|
404
|
+
prepend_args = array_to_arguments(prepend_args)
|
405
|
+
end
|
403
406
|
if args
|
404
407
|
prepend_args.append_argument(args)
|
405
408
|
args = prepend_args
|
@@ -408,6 +411,17 @@ module RubyLess
|
|
408
411
|
end
|
409
412
|
end
|
410
413
|
|
414
|
+
if append_args = opts[:append_args]
|
415
|
+
if append_args.kind_of?(Array)
|
416
|
+
append_args = array_to_arguments(append_args)
|
417
|
+
end
|
418
|
+
if args
|
419
|
+
args.append_argument(append_args)
|
420
|
+
else
|
421
|
+
args = append_args
|
422
|
+
end
|
423
|
+
end
|
424
|
+
|
411
425
|
if append_hash = opts[:append_hash]
|
412
426
|
last_arg = args.list.last
|
413
427
|
unless last_arg.klass.kind_of?(Hash)
|
@@ -422,5 +436,13 @@ module RubyLess
|
|
422
436
|
end
|
423
437
|
args
|
424
438
|
end
|
439
|
+
|
440
|
+
def array_to_arguments(args)
|
441
|
+
code = t('')
|
442
|
+
args.each do |arg|
|
443
|
+
code.append_argument(arg)
|
444
|
+
end
|
445
|
+
code
|
446
|
+
end
|
425
447
|
end
|
426
448
|
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.8.
|
8
|
+
s.version = "0.8.5"
|
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{2011-
|
12
|
+
s.date = %q{2011-07-11}
|
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 = [
|
data/test/RubyLess/basic.yml
CHANGED
@@ -118,10 +118,25 @@ instance_variable:
|
|
118
118
|
tem: "node.mazette"
|
119
119
|
res: "Mazette !"
|
120
120
|
|
121
|
-
|
122
|
-
src: "
|
123
|
-
tem: "add(10, 4)"
|
124
|
-
res: "
|
121
|
+
prepend_one:
|
122
|
+
src: "prepend_one(4) + prepend_one"
|
123
|
+
tem: "(add(10, 4)+add(10))"
|
124
|
+
res: "24"
|
125
|
+
|
126
|
+
prepend_many:
|
127
|
+
src: "prepend_many(4) + prepend_many"
|
128
|
+
tem: "(add(10, 20, 4)+add(10, 20))"
|
129
|
+
res: "64"
|
130
|
+
|
131
|
+
append_one:
|
132
|
+
src: "append_one(4) + append_one"
|
133
|
+
tem: "(add(4, 10)+add(10))"
|
134
|
+
res: "24"
|
135
|
+
|
136
|
+
append_many:
|
137
|
+
src: "append_many(4) + append_many"
|
138
|
+
tem: "(add(4, 10, 20)+add(10, 20))"
|
139
|
+
res: "64"
|
125
140
|
|
126
141
|
safe_property:
|
127
142
|
src: "dog_name"
|
data/test/RubyLess_test.rb
CHANGED
@@ -98,8 +98,14 @@ class RubyLessTest < Test::Unit::TestCase
|
|
98
98
|
# Example to dynamically rewrite method calls during compilation
|
99
99
|
def safe_method_type(signature, receiver = nil)
|
100
100
|
unless res = super
|
101
|
-
if signature == ['
|
101
|
+
if signature == ['prepend_one'] || signature == ['prepend_one', Number]
|
102
102
|
res ={:class => Number, :prepend_args => RubyLess::TypedString.new('10', :class => Number), :method => 'add'}
|
103
|
+
elsif signature == ['prepend_many'] || signature == ['prepend_many', Number]
|
104
|
+
res ={:class => Number, :prepend_args => [RubyLess::TypedString.new('10', :class => Number), RubyLess::TypedString.new('20', :class => Number)], :method => 'add'}
|
105
|
+
elsif signature == ['append_one'] || signature == ['append_one', Number]
|
106
|
+
res ={:class => Number, :append_args => RubyLess::TypedString.new('10', :class => Number), :method => 'add'}
|
107
|
+
elsif signature == ['append_many'] || signature == ['append_many', Number]
|
108
|
+
res ={:class => Number, :append_args => [RubyLess::TypedString.new('10', :class => Number), RubyLess::TypedString.new('20', :class => Number)], :method => 'add'}
|
103
109
|
elsif context && res = context[:node_class].safe_method_type(signature)
|
104
110
|
# try to execute method in the current var "var.method"
|
105
111
|
res = res[:class].call(self, signature) if res[:class].kind_of?(Proc)
|
@@ -145,8 +151,8 @@ class RubyLessTest < Test::Unit::TestCase
|
|
145
151
|
"str"
|
146
152
|
end
|
147
153
|
|
148
|
-
def add(
|
149
|
-
a+
|
154
|
+
def add(*args)
|
155
|
+
args.inject(0) {|s,a| s+a}
|
150
156
|
end
|
151
157
|
|
152
158
|
def vowel_count(str)
|
data/test/typed_string_test.rb
CHANGED
@@ -11,9 +11,16 @@ class TypedStringTest < Test::Unit::TestCase
|
|
11
11
|
should 'render with name' do
|
12
12
|
assert_equal 'foo', subject.to_s
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
should 'return class of content on klass' do
|
16
16
|
assert_equal Number, subject.klass
|
17
17
|
end
|
18
|
+
|
19
|
+
should 'maintain opts on dup' do
|
20
|
+
other = subject.dup
|
21
|
+
assert_equal TypedString, other.class
|
22
|
+
assert_equal subject.opts, other.opts
|
23
|
+
assert_equal subject.opts.object_id, other.opts.object_id
|
24
|
+
end
|
18
25
|
end
|
19
26
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubyless
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 53
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 8
|
9
|
-
-
|
10
|
-
version: 0.8.
|
9
|
+
- 5
|
10
|
+
version: 0.8.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Gaspard Bucher
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-07-11 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|