Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

not using attr_accessor function

  • Loading branch information...
commit 83c66bd5ec82a2033fadd7076c7a886d822c469d 1 parent 5991023
@tenderlove authored
View
6 History.txt
@@ -1,3 +1,9 @@
+=== 1.0.2
+
+* 1 bugfix
+
+ * Generating attribute functions that raise rather than attr_accessors
+
=== 1.0.1
* 1 bugfix
View
43 lib/zomg/idl/visitors/ruby_sexp.rb
@@ -16,11 +16,20 @@ def visit_Module(o)
def visit_Interface(o)
header = o.header.accept(self)
header = header ? [:block, header] : [:block]
+ o.children.each { |c|
+ list = c.accept(self)
+ if list
+ if list.first.is_a?(Symbol)
+ header << list
+ else
+ header += list
+ end
+ end
+ }
[ :module,
classify(o.header.name),
[:scope,
- header +
- o.children.map { |c| c.accept(self) }
+ header
]
]
end
@@ -50,11 +59,31 @@ def visit_Exception(o)
end
def visit_Attribute(o)
- [:fcall,
- o.readonly ? :attr_reader : :attr_accessor,
- [:array] +
- o.children.map { |c| [:lit, c.accept(self)] }
- ]
+ attributes = []
+ o.children.each { |name|
+ name = name.accept(self)
+
+ # Reader
+ attributes <<
+ [:defn, name.to_sym,
+ [:scope, [:block, [:args],
+ [:fcall, :raise, [:array,
+ [:call, [:const, :NotImplementedError], :new]]
+ ]
+ ]]
+ ]
+ unless o.readonly
+ attributes <<
+ [:defn, :"#{name}=",
+ [:scope, [:block, [:args, :_],
+ [:fcall, :raise, [:array,
+ [:call, [:const, :NotImplementedError], :new]]
+ ]
+ ]]
+ ]
+ end
+ }
+ attributes
end
def visit_ScopedName(o)
View
24 test/conversions/test_attribute.rb
@@ -19,10 +19,26 @@ def test_to_ruby_sexp
assert sexp
ruby_sexp =
[:block,
- [:module, :Foo,
- [:scope, [:block,
- [:fcall, :attr_accessor, [:array, [:lit, :awesome]]]
- ]]]]
+ [:module,
+ :Foo,
+ [:scope,
+ [:block,
+ [:defn,
+ :awesome,
+ [:scope,
+ [:block,
+ [:args],
+ [:fcall,
+ :raise,
+ [:array, [:call, [:const, :NotImplementedError], :new]]]]]],
+ [:defn,
+ :awesome=,
+ [:scope,
+ [:block,
+ [:args, :_],
+ [:fcall,
+ :raise,
+ [:array, [:call, [:const, :NotImplementedError], :new]]]]]]]]]]
assert_equal(ruby_sexp, sexp)
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.