rubyless 0.2.0 → 0.3.0

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/tasks/spec.rake ADDED
@@ -0,0 +1,54 @@
1
+
2
+ if HAVE_SPEC_RAKE_SPECTASK and not PROJ.spec.files.to_a.empty?
3
+ require 'spec/rake/verify_rcov'
4
+
5
+ namespace :spec do
6
+
7
+ desc 'Run all specs with basic output'
8
+ Spec::Rake::SpecTask.new(:run) do |t|
9
+ t.ruby_opts = PROJ.ruby_opts
10
+ t.spec_opts = PROJ.spec.opts
11
+ t.spec_files = PROJ.spec.files
12
+ t.libs += PROJ.libs
13
+ end
14
+
15
+ desc 'Run all specs with text output'
16
+ Spec::Rake::SpecTask.new(:specdoc) do |t|
17
+ t.ruby_opts = PROJ.ruby_opts
18
+ t.spec_opts = PROJ.spec.opts + ['--format', 'specdoc']
19
+ t.spec_files = PROJ.spec.files
20
+ t.libs += PROJ.libs
21
+ end
22
+
23
+ if HAVE_RCOV
24
+ desc 'Run all specs with RCov'
25
+ Spec::Rake::SpecTask.new(:rcov) do |t|
26
+ t.ruby_opts = PROJ.ruby_opts
27
+ t.spec_opts = PROJ.spec.opts
28
+ t.spec_files = PROJ.spec.files
29
+ t.libs += PROJ.libs
30
+ t.rcov = true
31
+ t.rcov_dir = PROJ.rcov.dir
32
+ t.rcov_opts = PROJ.rcov.opts + ['--exclude', 'spec']
33
+ end
34
+
35
+ RCov::VerifyTask.new(:verify) do |t|
36
+ t.threshold = PROJ.rcov.threshold
37
+ t.index_html = File.join(PROJ.rcov.dir, 'index.html')
38
+ t.require_exact_threshold = PROJ.rcov.threshold_exact
39
+ end
40
+
41
+ task :verify => :rcov
42
+ remove_desc_for_task %w(spec:clobber_rcov)
43
+ end
44
+
45
+ end # namespace :spec
46
+
47
+ desc 'Alias to spec:run'
48
+ task :spec => 'spec:run'
49
+
50
+ task :clobber => 'spec:clobber_rcov' if HAVE_RCOV
51
+
52
+ end # if HAVE_SPEC_RAKE_SPECTASK
53
+
54
+ # EOF
data/tasks/svn.rake ADDED
@@ -0,0 +1,47 @@
1
+
2
+ if HAVE_SVN
3
+
4
+ unless PROJ.svn.root
5
+ info = %x/svn info ./
6
+ m = %r/^Repository Root:\s+(.*)$/.match(info)
7
+ PROJ.svn.root = (m.nil? ? '' : m[1])
8
+ end
9
+ PROJ.svn.root = File.join(PROJ.svn.root, PROJ.svn.path) unless PROJ.svn.path.empty?
10
+
11
+ namespace :svn do
12
+
13
+ # A prerequisites task that all other tasks depend upon
14
+ task :prereqs
15
+
16
+ desc 'Show tags from the SVN repository'
17
+ task :show_tags => 'svn:prereqs' do |t|
18
+ tags = %x/svn list #{File.join(PROJ.svn.root, PROJ.svn.tags)}/
19
+ tags.gsub!(%r/\/$/, '')
20
+ tags = tags.split("\n").sort {|a,b| b <=> a}
21
+ puts tags
22
+ end
23
+
24
+ desc 'Create a new tag in the SVN repository'
25
+ task :create_tag => 'svn:prereqs' do |t|
26
+ v = ENV['VERSION'] or abort 'Must supply VERSION=x.y.z'
27
+ abort "Versions don't match #{v} vs #{PROJ.version}" if v != PROJ.version
28
+
29
+ svn = PROJ.svn
30
+ trunk = File.join(svn.root, svn.trunk)
31
+ tag = "%s-%s" % [PROJ.name, PROJ.version]
32
+ tag = File.join(svn.root, svn.tags, tag)
33
+ msg = "Creating tag for #{PROJ.name} version #{PROJ.version}"
34
+
35
+ puts "Creating SVN tag '#{tag}'"
36
+ unless system "svn cp -m '#{msg}' #{trunk} #{tag}"
37
+ abort "Tag creation failed"
38
+ end
39
+ end
40
+
41
+ end # namespace :svn
42
+
43
+ task 'gem:release' => 'svn:create_tag'
44
+
45
+ end # if PROJ.svn.path
46
+
47
+ # EOF
data/tasks/test.rake ADDED
@@ -0,0 +1,40 @@
1
+
2
+ if test(?e, PROJ.test.file) or not PROJ.test.files.to_a.empty?
3
+ require 'rake/testtask'
4
+
5
+ namespace :test do
6
+
7
+ Rake::TestTask.new(:run) do |t|
8
+ t.libs = PROJ.libs
9
+ t.test_files = if test(?f, PROJ.test.file) then [PROJ.test.file]
10
+ else PROJ.test.files end
11
+ t.ruby_opts += PROJ.ruby_opts
12
+ t.ruby_opts += PROJ.test.opts
13
+ end
14
+
15
+ if HAVE_RCOV
16
+ desc 'Run rcov on the unit tests'
17
+ task :rcov => :clobber_rcov do
18
+ opts = PROJ.rcov.opts.dup << '-o' << PROJ.rcov.dir
19
+ opts = opts.join(' ')
20
+ files = if test(?f, PROJ.test.file) then [PROJ.test.file]
21
+ else PROJ.test.files end
22
+ files = files.join(' ')
23
+ sh "#{RCOV} #{files} #{opts}"
24
+ end
25
+
26
+ task :clobber_rcov do
27
+ rm_r 'coverage' rescue nil
28
+ end
29
+ end
30
+
31
+ end # namespace :test
32
+
33
+ desc 'Alias to test:run'
34
+ task :test => 'test:run'
35
+
36
+ task :clobber => 'test:clobber_rcov' if HAVE_RCOV
37
+
38
+ end
39
+
40
+ # EOF
@@ -0,0 +1,36 @@
1
+ if HAVE_ZENTEST
2
+
3
+ # --------------------------------------------------------------------------
4
+ if test(?e, PROJ.test.file) or not PROJ.test.files.to_a.empty?
5
+ require 'autotest'
6
+
7
+ namespace :test do
8
+ task :autotest do
9
+ Autotest.run
10
+ end
11
+ end
12
+
13
+ desc "Run the autotest loop"
14
+ task :autotest => 'test:autotest'
15
+
16
+ end # if test
17
+
18
+ # --------------------------------------------------------------------------
19
+ if HAVE_SPEC_RAKE_SPECTASK and not PROJ.spec.files.to_a.empty?
20
+ require 'autotest/rspec'
21
+
22
+ namespace :spec do
23
+ task :autotest do
24
+ load '.autotest' if test(?f, '.autotest')
25
+ Autotest::Rspec.run
26
+ end
27
+ end
28
+
29
+ desc "Run the autotest loop"
30
+ task :autotest => 'spec:autotest'
31
+
32
+ end # if rspec
33
+
34
+ end # if HAVE_ZENTEST
35
+
36
+ # EOF
@@ -18,6 +18,14 @@ dynamic_string_again:
18
18
  src: "now.strftime(\"#{name}\")"
19
19
  tem: "Time.now.strftime(\"#{var1.name}\")"
20
20
 
21
+ symbol:
22
+ src: ":foobar"
23
+ sxp: 's(:lit, :foobar)'
24
+
25
+ hash_access:
26
+ src: "dictionary[:key]"
27
+ tem: "get_dict[:key]"
28
+
21
29
  rewrite_variables:
22
30
  src: "!prev.ancestor?(main) && !node.ancestor?(main)"
23
31
  tem: "(not previous.ancestor?(@node) and not var1.ancestor?(@node))"
@@ -49,12 +57,12 @@ method_on_method:
49
57
  src: "project.name.to_s"
50
58
  tem: "var1.project.name.to_s"
51
59
  res: 'project'
52
-
60
+
53
61
  comp_ternary_op:
54
62
  src: "1 > 2 ? 'foo' : 'bar'"
55
63
  tem: "(1>2) ? \"foo\" : \"bar\""
56
64
  res: "bar"
57
-
65
+
58
66
  method_ternary_op:
59
67
  src: "id > 2 ? 'foo' : 'bar'"
60
68
  tem: "(var1.zip>2) ? \"foo\" : \"bar\""
@@ -63,15 +71,15 @@ method_ternary_op:
63
71
  method_argument_can_be_nil:
64
72
  src: "vowel_count(spouse.name)"
65
73
  tem: "(var1.spouse ? vowel_count(var1.spouse.name) : nil)"
66
-
74
+
67
75
  multi_arg_method_argument_can_be_nil:
68
76
  src: "log_info(spouse, 'foobar')"
69
77
  tem: "(var1.spouse ? log_info(var1.spouse, \"foobar\") : nil)"
70
-
78
+
71
79
  multi_arg_method_arguments_can_be_nil:
72
80
  src: "log_info(husband, spouse.name)"
73
81
  tem: "((var1.husband && var1.spouse) ? log_info(var1.husband, var1.spouse.name) : nil)"
74
-
82
+
75
83
  multi_arg_method_arguments_can_be_nil_same_condition:
76
84
  src: "log_info(spouse, spouse.name)"
77
85
  tem: "(var1.spouse ? log_info(var1.spouse, var1.spouse.name) : nil)"
@@ -17,4 +17,16 @@ looping:
17
17
 
18
18
  add_two_strings:
19
19
  src: "name + 14"
20
- res: "'var1.name' does not respond to '+(14)'."
20
+ res: "'var1.name' does not respond to '+(Number)'."
21
+
22
+ two_arguments_in_hash:
23
+ src: "dictionary[:one, :two]"
24
+ res: "'get_dict' does not respond to '[](Symbol, Symbol)'."
25
+
26
+ number_argument:
27
+ src: "dictionary[43]"
28
+ res: "'get_dict' does not respond to '[](Number)'."
29
+
30
+ string_argument:
31
+ src: "dictionary[spouse.name]"
32
+ res: "'get_dict' does not respond to '[](String)'."
@@ -1,6 +1,11 @@
1
1
  require 'date'
2
2
  require File.dirname(__FILE__) + '/test_helper.rb'
3
3
 
4
+ class StringDictionary
5
+ include RubyLess::SafeClass
6
+ safe_method [:[], Symbol] => {:class => String, :nil => true}
7
+ end
8
+
4
9
  class SimpleHelper < Test::Unit::TestCase
5
10
  attr_reader :context
6
11
  yamltest :src_from_title => false
@@ -10,12 +15,13 @@ class SimpleHelper < Test::Unit::TestCase
10
15
  safe_method :node => lambda {|h| {:class => h.context[:node_class], :method => h.context[:node]}}
11
16
  safe_method :now => {:class => Time, :method => "Time.now"}
12
17
  safe_method :birth => {:class => Time, :method => "Date.parse('2009-06-02 18:44')"}
13
- safe_method [:vowel_count, String] => RubyLess::Number
18
+ safe_method :dictionary => {:class => StringDictionary, :method => 'get_dict'}
19
+ safe_method [:vowel_count, String] => Number
14
20
  safe_method [:log_info, Dummy, String] => String
15
- safe_method_for String, [:==, String] => RubyLess::Boolean
21
+ safe_method_for String, [:==, String] => Boolean
16
22
  safe_method_for String, [:to_s] => String
17
23
  safe_method_for Time, [:strftime, String] => String
18
-
24
+
19
25
  # Example to dynamically rewrite method calls during compilation
20
26
  def safe_method_type(signature)
21
27
  unless res = self.class.safe_method_type(signature)
@@ -27,26 +33,26 @@ class SimpleHelper < Test::Unit::TestCase
27
33
  end
28
34
  res
29
35
  end
30
-
36
+
31
37
  def var1
32
38
  Dummy.new
33
39
  end
34
-
40
+
35
41
  def vowel_count(str)
36
42
  str.tr('^aeiouy', '').size
37
43
  end
38
-
44
+
39
45
  def log_info(obj, msg)
40
46
  "[#{obj.name}] #{msg}"
41
47
  end
42
-
48
+
43
49
  def yt_do_test(file, test, context = yt_get('context',file,test))
44
50
  @@test_strings[file][test].keys.each do |key|
45
51
  next if ['src', 'context'].include?(key)
46
52
  yt_assert yt_get(key,file,test), parse(key, file, test, context)
47
53
  end
48
54
  end
49
-
55
+
50
56
  def parse(key, file, test, opts)
51
57
  @context = {:node => 'var1', :node_class => Dummy}
52
58
  source = yt_get('src', file, test)
@@ -55,6 +61,8 @@ class SimpleHelper < Test::Unit::TestCase
55
61
  source ? RubyLess.translate(source, self) : yt_get('tem', file, test)
56
62
  when 'res'
57
63
  eval(source ? RubyLess.translate(source, self) : yt_get('tem', file, test)).to_s
64
+ when 'sxp'
65
+ RubyParser.new.parse(source).inspect
58
66
  else
59
67
  "Unknown key '#{key}'. Should be 'tem' or 'res'."
60
68
  end
@@ -63,6 +71,6 @@ class SimpleHelper < Test::Unit::TestCase
63
71
  # puts err.backtrace
64
72
  err.message
65
73
  end
66
-
74
+
67
75
  yt_make
68
76
  end
@@ -4,14 +4,15 @@ class Dummy < RubyLess::ActiveRecordMock
4
4
  attr_reader :name
5
5
  include RubyLess::SafeClass
6
6
 
7
- safe_method [:ancestor?, Dummy] => RubyLess::Boolean
8
- safe_method :parent => {:class => 'Dummy', :special_option => 'foobar'},
9
- :children => ['Dummy'],
10
- :project => 'Dummy',
11
- :spouse => {:class => 'Dummy', :nil => true},
12
- :husband => {:class => 'Dummy', :nil => true},
13
- :id => {:class => RubyLess::Number, :method => :zip},
14
- :name => String
7
+ safe_method [:ancestor?, Dummy] => Boolean
8
+ safe_method :parent => {:class => 'Dummy', :special_option => 'foobar'},
9
+ :children => ['Dummy'],
10
+ :project => 'Dummy',
11
+ :id => {:class => Number, :method => :zip},
12
+ :name => String
13
+ safe_method :defaults => {:nil => true},
14
+ :spouse => 'Dummy',
15
+ :husband => {:class => 'Dummy'}
15
16
 
16
17
  safe_attribute :age, :friend_id, :log_at, :format
17
18
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubyless
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gaspard Bucher
@@ -9,43 +9,98 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-02 00:00:00 +02:00
12
+ date: 2009-10-03 00:00:00 +02:00
13
13
  default_executable:
14
- dependencies: []
15
-
16
- description:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: ruby_parser
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.0.4
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: sexp_processor
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 3.0.1
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: bones
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 2.5.1
44
+ version:
45
+ - !ruby/object:Gem::Dependency
46
+ name: yamltest
47
+ type: :development
48
+ version_requirement:
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: 0.5.3
54
+ version:
55
+ description: |-
56
+ RubyLess is an interpreter for "safe ruby". The idea is to transform some "unsafe" ruby code into safe, type checked
57
+ ruby, eventually rewriting some variables or methods.
17
58
  email: gaspard@teti.ch
18
59
  executables: []
19
60
 
20
61
  extensions: []
21
62
 
22
63
  extra_rdoc_files:
23
- - README.rdoc
64
+ - History.txt
65
+ - README.txt
24
66
  files:
25
67
  - History.txt
68
+ - README.txt
26
69
  - Rakefile
27
- - README.rdoc
70
+ - lib/basic_types.rb
71
+ - lib/processor.rb
72
+ - lib/rubyless.rb
73
+ - lib/safe_class.rb
74
+ - lib/typed_string.rb
28
75
  - rubyless.gemspec
29
- - test/mock
30
- - test/mock/active_record_mock.rb
31
- - test/mock/dummy_class.rb
32
- - test/RubyLess
76
+ - tasks/ann.rake
77
+ - tasks/bones.rake
78
+ - tasks/gem.rake
79
+ - tasks/git.rake
80
+ - tasks/notes.rake
81
+ - tasks/post_load.rake
82
+ - tasks/rdoc.rake
83
+ - tasks/rubyforge.rake
84
+ - tasks/setup.rb
85
+ - tasks/spec.rake
86
+ - tasks/svn.rake
87
+ - tasks/test.rake
88
+ - tasks/zentest.rake
33
89
  - test/RubyLess/active_record.yml
34
90
  - test/RubyLess/basic.yml
35
91
  - test/RubyLess/errors.yml
36
92
  - test/RubyLess_test.rb
93
+ - test/mock/active_record_mock.rb
94
+ - test/mock/dummy_class.rb
37
95
  - test/test_helper.rb
38
- - lib/basic_types.rb
39
- - lib/processor.rb
40
- - lib/rubyless.rb
41
- - lib/safe_class.rb
42
- - lib/typed_string.rb
43
96
  has_rdoc: true
44
97
  homepage: http://zenadmin.org/546
98
+ licenses: []
99
+
45
100
  post_install_message:
46
101
  rdoc_options:
47
102
  - --main
48
- - README.rdoc
103
+ - README.txt
49
104
  require_paths:
50
105
  - lib
51
106
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -63,9 +118,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
63
118
  requirements: []
64
119
 
65
120
  rubyforge_project: rubyless
66
- rubygems_version: 1.3.1
121
+ rubygems_version: 1.3.5
67
122
  signing_key:
68
- specification_version: 2
69
- summary: 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
70
- test_files: []
71
-
123
+ specification_version: 3
124
+ summary: RubyLess is an interpreter for "safe ruby"
125
+ test_files:
126
+ - test/test_helper.rb