metaruby 1.0.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 209d7c5d2bfb1aef6d4370e9b87d5635f4cbe093
4
- data.tar.gz: ebbba741e3cb1511ebf7f05a6e4e4d242b23ffda
3
+ metadata.gz: d4a39a36eff3dfcc3885b69729b7fc1f20d08803
4
+ data.tar.gz: 2d6a47cba4d1e6658aabd7a54f682d62e9cfc7c0
5
5
  SHA512:
6
- metadata.gz: 6fffccb4135deee4fa523fc09b79a9ab66eb8783ec7de35bc88a29876842909210795adca46afc8514b4ae28de51ed9c4045a0e8f54da06cf8948424629edc2c
7
- data.tar.gz: 2b832a3185e0b0a4c657979a1b0a86f362541d4cb09364355b40c50d7bbcd86de4fe5356131f36af6d669ea8dd08f7d7faadb5710d303abff23d1ff488d0779c
6
+ metadata.gz: 0ef497f6483f83756ede50becd59106c9bd5c87700172fb1de2090bfe9e0ee56317c50a0e4c6e7d9ee71a8a74e3d497a23bcb76bd8c15572c5ab1a1f27947e66
7
+ data.tar.gz: 32ed5a1675c2598bdba4690ab9214bfe39b5c4125e04b0a825f2513cedaceb5a4297bab53a1393e5a0fe910143ea53efebc5cc11e9792830e66525f58be2dff5
@@ -1,11 +1,14 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
- - 2.0.0
5
4
  - 2.1.6
6
5
  - 2.2.2
7
- - 2.3.0
8
- - jruby-9.0.4.0
6
+ - 2.3.3
7
+ - 2.4.1
8
+ - jruby-9.1.13.0
9
9
  script:
10
10
  - bundle exec rake
11
11
  - bundle exec rake test
12
+ allow_failures:
13
+ - rvm: jruby-9.1.13.0
14
+ bundler_args: --without gui
data/Gemfile CHANGED
@@ -1,3 +1,9 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ platform :mri do
4
+ group 'gui' do
5
+ gem 'qtbindings'
6
+ end
7
+ end
8
+
3
9
  gemspec
data/Rakefile CHANGED
@@ -3,11 +3,21 @@ require "rake/testtask"
3
3
 
4
4
  task :default
5
5
 
6
+ has_gui = begin
7
+ require 'Qt'
8
+ true
9
+ rescue LoadError
10
+ false
11
+ end
12
+
6
13
  Rake::TestTask.new(:test) do |t|
7
14
  t.libs << "lib"
8
15
  t.libs << "."
9
- t.ruby_opts << '-w'
10
- t.test_files = FileList['test/suite.rb']
16
+
17
+ file_list = FileList['test/**/test_*.rb']
18
+ if !has_gui
19
+ file_list.exclude('test/gui/**/test_*.rb')
20
+ end
11
21
  end
12
22
 
13
23
  task :gem => :build
@@ -1,6 +1,8 @@
1
1
  require 'utilrb/object/attribute'
2
2
  require 'weakref'
3
3
 
4
+ require 'metaruby/backward/singleton_class_p'
5
+
4
6
  require 'metaruby/attributes'
5
7
  require 'metaruby/registration'
6
8
  require 'metaruby/model_as_module'
@@ -23,8 +23,6 @@ module MetaRuby
23
23
  # @example promotion to update back references
24
24
  # class Port; attr_accessor :component_model end
25
25
  # class Component
26
- # inherited_attribute(:ports, :port, map: true) { Hash.new }
27
- #
28
26
  # # Update #component_model to make it point to the receiver instead
29
27
  # # of the original model. Note that metaruby does not memoize the
30
28
  # # result, so it has to be done in the promote method if it is
@@ -34,6 +32,8 @@ module MetaRuby
34
32
  # port.component_model = self
35
33
  # port
36
34
  # end
35
+ #
36
+ # inherited_attribute(:ports, :port, map: true) { Hash.new }
37
37
  # end
38
38
  module Attributes
39
39
  def included(mod)
@@ -72,6 +72,21 @@ module MetaRuby
72
72
  nil
73
73
  end
74
74
 
75
+ ANCESTORS_ACCESS =
76
+ if RUBY_VERSION < "2.1.0"
77
+ <<-EOCODE
78
+ ancestors = self.ancestors
79
+ if ancestors.first != self
80
+ ancestors.unshift self
81
+ end
82
+ EOCODE
83
+ else
84
+ <<-EOCODE
85
+ ancestors = self.ancestors
86
+ EOCODE
87
+ end
88
+
89
+
75
90
  # @api private
76
91
  #
77
92
  # Helper method for {#inherited_single_value_attribute} in case there
@@ -79,10 +94,7 @@ module MetaRuby
79
94
  def define_single_value_without_promotion(method_name, ivar)
80
95
  class_eval <<-EOF, __FILE__, __LINE__+1
81
96
  def #{method_name}
82
- ancestors = self.ancestors
83
- if ancestors.first != self
84
- ancestors.unshift self
85
- end
97
+ #{ANCESTORS_ACCESS}
86
98
 
87
99
  has_value = false
88
100
  for klass in ancestors
@@ -118,10 +130,7 @@ module MetaRuby
118
130
  def define_single_value_with_promotion(method_name, promotion_method_name, ivar)
119
131
  class_eval <<-EOF, __FILE__, __LINE__+1
120
132
  def #{method_name}
121
- ancestors = self.ancestors
122
- if ancestors.first != self
123
- ancestors.unshift self
124
- end
133
+ #{ANCESTORS_ACCESS}
125
134
 
126
135
  promotions = []
127
136
  for klass in ancestors
@@ -130,7 +139,7 @@ module MetaRuby
130
139
  value = klass.instance_variable_get(:#{ivar})
131
140
  break
132
141
  end
133
- promotions.unshift(klass) if klass.respond_to?("#{promotion_method_name}")
142
+ promotions.unshift(klass) if klass.respond_to?(:#{promotion_method_name})
134
143
  end
135
144
  if !has_value && respond_to?(:#{method_name}_default)
136
145
  # Look for default
@@ -281,13 +290,10 @@ module MetaRuby
281
290
  nil
282
291
  end
283
292
  def has_#{name}?(key)
284
- ancestors = self.ancestors
285
- if ancestors.first != self
286
- ancestors.unshift self
287
- end
293
+ #{ANCESTORS_ACCESS}
288
294
  for klass in ancestors
289
- if klass.instance_variable_defined?(:@#{attribute_name})
290
- return true if klass.#{attribute_name}.has_key?(key)
295
+ if attr = klass.instance_variable_get(:@#{attribute_name})
296
+ return true if attr.has_key?(key)
291
297
  end
292
298
  end
293
299
  false
@@ -305,8 +311,8 @@ module MetaRuby
305
311
  def clear_#{attribute_name}
306
312
  #{attribute_name}.clear
307
313
  for klass in ancestors
308
- if klass.instance_variable_defined?(:@#{attribute_name})
309
- klass.#{attribute_name}.clear
314
+ if attr = klass.instance_variable_get(:@#{attribute_name})
315
+ attr.clear
310
316
  end
311
317
  end
312
318
  end
@@ -338,23 +344,20 @@ module MetaRuby
338
344
  return enum_for(:each_#{name}, key, uniq)
339
345
  end
340
346
 
341
- ancestors = self.ancestors
342
- if ancestors.first != self
343
- ancestors.unshift self
344
- end
347
+ #{ANCESTORS_ACCESS}
345
348
  if key
346
349
  for klass in ancestors
347
- if klass.instance_variable_defined?(:@#{attribute_name})
348
- if klass.#{attribute_name}.has_key?(key)
349
- yield(klass.#{attribute_name}[key])
350
+ if attr = klass.instance_variable_get(:@#{attribute_name})
351
+ if attr.has_key?(key)
352
+ yield(attr[key])
350
353
  return self if uniq
351
354
  end
352
355
  end
353
356
  end
354
357
  elsif !uniq
355
358
  for klass in ancestors
356
- if klass.instance_variable_defined?(:@#{attribute_name})
357
- klass.#{attribute_name}.#{enum_with} do |el|
359
+ if attr = klass.instance_variable_get(:@#{attribute_name})
360
+ attr.#{enum_with} do |el|
358
361
  yield(el)
359
362
  end
360
363
  end
@@ -362,8 +365,8 @@ module MetaRuby
362
365
  else
363
366
  seen = Set.new
364
367
  for klass in ancestors
365
- if klass.instance_variable_defined?(:@#{attribute_name})
366
- klass.#{attribute_name}.#{enum_with} do |el_key, el|
368
+ if attr = klass.instance_variable_get(:@#{attribute_name})
369
+ attr.#{enum_with} do |el_key, el|
367
370
  if !seen.include?(el_key)
368
371
  seen << el_key
369
372
  #{if yield_key then 'yield(el_key, el)' else 'yield(el)' end}
@@ -386,17 +389,12 @@ module MetaRuby
386
389
  def self.nomap_without_promotion(name, attribute_name, enum_with: :each)
387
390
  code, file, line =<<-EOF, __FILE__, __LINE__+1
388
391
  def each_#{name}
389
- if !block_given?
390
- return enum_for(:each_#{name})
391
- end
392
+ return enum_for(__method__) if !block_given?
392
393
 
393
- ancestors = self.ancestors
394
- if ancestors.first != self
395
- ancestors.unshift self
396
- end
394
+ #{ANCESTORS_ACCESS}
397
395
  for klass in ancestors
398
- if klass.instance_variable_defined?(:@#{attribute_name})
399
- klass.#{attribute_name}.#{enum_with} { |el| yield(el) }
396
+ if attr = klass.instance_variable_get(:@#{attribute_name})
397
+ attr.#{enum_with} { |el| yield(el) }
400
398
  end
401
399
  end
402
400
  self
@@ -416,16 +414,13 @@ module MetaRuby
416
414
  return enum_for(:each_#{name}, key, uniq)
417
415
  end
418
416
 
419
- ancestors = self.ancestors
420
- if ancestors.first != self
421
- ancestors.unshift self
422
- end
417
+ #{ANCESTORS_ACCESS}
423
418
  if key
424
419
  promotions = []
425
420
  for klass in ancestors
426
- if klass.instance_variable_defined?(:@#{attribute_name})
427
- if klass.#{attribute_name}.has_key?(key)
428
- value = klass.#{attribute_name}[key]
421
+ if attr = klass.instance_variable_get(:@#{attribute_name})
422
+ if attr.has_key?(key)
423
+ value = attr[key]
429
424
  for p in promotions
430
425
  value = p.promote_#{name}(key, value)
431
426
  end
@@ -433,27 +428,27 @@ module MetaRuby
433
428
  return self if uniq
434
429
  end
435
430
  end
436
- promotions.unshift(klass) if klass.respond_to?("promote_#{name}")
431
+ promotions.unshift(klass) if klass.respond_to?(:promote_#{name})
437
432
  end
438
433
  elsif !uniq
439
434
  promotions = []
440
435
  for klass in ancestors
441
- if klass.instance_variable_defined?(:@#{attribute_name})
442
- klass.#{attribute_name}.#{enum_with} do |k, v|
436
+ if attr = klass.instance_variable_get(:@#{attribute_name})
437
+ attr.#{enum_with} do |k, v|
443
438
  for p in promotions
444
439
  v = p.promote_#{name}(k, v)
445
440
  end
446
441
  #{if yield_key then 'yield(k, v)' else 'yield(v)' end}
447
442
  end
448
443
  end
449
- promotions.unshift(klass) if klass.respond_to?("promote_#{name}")
444
+ promotions.unshift(klass) if klass.respond_to?(:promote_#{name})
450
445
  end
451
446
  else
452
447
  seen = Set.new
453
448
  promotions = []
454
449
  for klass in ancestors
455
- if klass.instance_variable_defined?(:@#{attribute_name})
456
- klass.#{attribute_name}.#{enum_with} do |k, v|
450
+ if attr = klass.instance_variable_get(:@#{attribute_name})
451
+ attr.#{enum_with} do |k, v|
457
452
  unless seen.include?(k)
458
453
  for p in promotions
459
454
  v = p.promote_#{name}(k, v)
@@ -463,7 +458,7 @@ module MetaRuby
463
458
  end
464
459
  end
465
460
  end
466
- promotions.unshift(klass) if klass.respond_to?("promote_#{name}")
461
+ promotions.unshift(klass) if klass.respond_to?(:promote_#{name})
467
462
  end
468
463
  end
469
464
  self
@@ -483,21 +478,18 @@ module MetaRuby
483
478
  return enum_for(:each_#{name})
484
479
  end
485
480
 
486
- ancestors = self.ancestors
487
- if ancestors.first != self
488
- ancestors.unshift self
489
- end
481
+ #{ANCESTORS_ACCESS}
490
482
  promotions = []
491
483
  for klass in ancestors
492
- if klass.instance_variable_defined?(:@#{attribute_name})
493
- klass.#{attribute_name}.#{enum_with} do |value|
484
+ if attr = klass.instance_variable_get(:@#{attribute_name})
485
+ attr.#{enum_with} do |value|
494
486
  for p in promotions
495
487
  value = p.promote_#{name}(value)
496
488
  end
497
489
  yield(value)
498
490
  end
499
491
  end
500
- promotions.unshift(klass) if klass.respond_to?("promote_#{name}")
492
+ promotions.unshift(klass) if klass.respond_to?(:promote_#{name})
501
493
  end
502
494
  self
503
495
  end
@@ -0,0 +1,14 @@
1
+ class Module
2
+ if !method_defined?(:singleton_class?)
3
+ # It so happens that this method to determine whether a class is a
4
+ # singleton class is valid for ruby 2.0 and breaks on 2.1 ... However
5
+ # (!) on 2.1 singleton_class? is defined
6
+ def singleton_class?
7
+ if instance_variable_defined?(:@__singleton_class)
8
+ @__singleton_class
9
+ else
10
+ @__singleton_class = (ancestors.first != self)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -2,7 +2,37 @@ require 'metaruby/dsls/doc'
2
2
  require 'metaruby/dsls/find_through_method_missing'
3
3
 
4
4
  module MetaRuby
5
- # Helper functions to build DSLs
5
+ # DSLs-related tools
6
+ #
7
+ # == Find through method missing
8
+ #
9
+ # The find through method missing functionality is meant to allow classes to
10
+ # turn objects that can be found (with a method that finds an object by its
11
+ # name) into an attribute call as e.g.
12
+ #
13
+ # task.test_event # => task.find_event("test")
14
+ #
15
+ # See {DSLs::FindThroughMethodMissing} for a complete description
16
+ #
17
+ # == Documentation parsing
18
+ #
19
+ # This provides the logic to find a documentation block above a DSL-like
20
+ # object creation. For instance, given a class that looks like
21
+ #
22
+ # class Task
23
+ # def event(name) # creates an event object with the given name
24
+ # end
25
+ # end
26
+ #
27
+ # Used in a DSL context like so:
28
+ #
29
+ # # The test event allows us
30
+ # #
31
+ # # To provide an example
32
+ # event 'test'
33
+ #
34
+ # The parse_documentation method allows to extract the comment block above
35
+ # the 'event' call. See {DSLs.parse_documentation} for more information
6
36
  module DSLs
7
37
  end
8
38
  end
@@ -10,21 +10,34 @@ module MetaRuby
10
10
  # the element whose documentation we are looking for.
11
11
  # @return [String,nil] the parsed documentation, or nil if there is no
12
12
  # documentation
13
+ #
14
+ # @example find the documentation block of an event creation
15
+ # # assuming the following toplevel DSL code in a file called test.orogen
16
+ # task "Task" do
17
+ # # Just an example event
18
+ # event "test"
19
+ # end
20
+ #
21
+ # # One would use the following code to extract the documentation
22
+ # # above the test event declaration. The call must be made within the
23
+ # # event creation code
24
+ # MetaRuby::DSLs.parse_documentation_block(/test\.orogen$/, "event")
25
+ #
13
26
  def self.parse_documentation_block(file_match, trigger_method = /.*/)
14
27
  last_method_matched = false
15
- call_stack.each do |call|
28
+ caller_locations(1).each do |call|
16
29
  this_method_matched =
17
- if trigger_method === call[2].to_s
30
+ if trigger_method === call.label
18
31
  true
19
- elsif call[2] == :method_missing
32
+ elsif call.label == 'method_missing'
20
33
  last_method_matched
21
34
  else
22
35
  false
23
36
  end
24
37
 
25
- if !this_method_matched && last_method_matched && (file_match === call[0])
26
- if File.file?(call[0])
27
- return parse_documentation_block_at(call[0], call[1])
38
+ if !this_method_matched && last_method_matched && (file_match === call.absolute_path)
39
+ if File.file?(call.absolute_path)
40
+ return parse_documentation_block_at(call.absolute_path, call.lineno)
28
41
  else return
29
42
  end
30
43
  end
@@ -47,31 +60,26 @@ module MetaRuby
47
60
  # Lines are given 1-based (as all editors work that way), and we
48
61
  # want the line before the definition. Remove two
49
62
  line = line - 2
63
+
64
+ space_count = nil
50
65
  while true
51
- case l = lines[line]
52
- when /^\s*$/
53
- break
54
- when /^\s*#/
55
- block << l
66
+ l = lines[line]
67
+ comment_match = /^\s*#/.match(l)
68
+ if comment_match
69
+ comment_line = comment_match.post_match.rstrip
70
+ stripped_line = comment_line.lstrip
71
+ leading_spaces = comment_line.size - stripped_line.size
72
+ if !stripped_line.empty? && (!space_count || space_count > leading_spaces)
73
+ space_count = leading_spaces
74
+ end
75
+ block.unshift(comment_line)
56
76
  else break
57
77
  end
58
78
  line = line - 1
59
79
  end
60
- block = block.map do |l|
61
- l.strip.gsub(/^\s*#/, '')
62
- end
63
- # Now remove the same amount of spaces in front of each lines
64
- space_count = block.map do |l|
65
- l =~ /^(\s*)/
66
- if $1.size != l.size
67
- $1.size
68
- end
69
- end.compact.min
70
- block = block.map do |l|
71
- l[space_count..-1]
72
- end
73
80
  if !block.empty?
74
- block.reverse.join("\n")
81
+ space_count ||= 0
82
+ block.map { |l| l[space_count..-1] }.join("\n")
75
83
  end
76
84
  end
77
85
  end