Skip to content

Commit

Permalink
add conversion of type to full specification
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed Feb 13, 2013
1 parent e6ebe80 commit 6ac5fdc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/ruby/ycp/exportable.rb
Expand Up @@ -12,6 +12,11 @@ def published_variables

def publish options
raise "Missing signature" unless options[:type]
# convert type to full specification
type = options[:type].delete " \t"
type = type.gsub(/map([^<]|$)/,'map<any,any>\\1')
type = type.gsub(/list([^<]|$)/,'list<any>\\1')
options[:type] = type
if options[:function]
published_functions[options[:function]] = OpenStruct.new options
elsif options[:variable]
Expand Down
12 changes: 9 additions & 3 deletions tests/ruby/exportable_test.rb
Expand Up @@ -5,7 +5,8 @@

class MyTestClass
extend YCP::Exportable
publish :variable => :variable_a, :type => "map<symbol,any>"
publish :variable => :complex, :type => "map< string, map<list, map> >"
publish :variable => :variable_a, :type => "map"
def initialize
self.variable_a = { :test => "lest" }
end
Expand All @@ -26,12 +27,17 @@ def test_publish_methods
end

def test_publish_variables
assert_equal [:variable_a], MyTest.class.published_variables.keys
assert_equal "map<symbol,any>", MyTest.class.published_variables[:variable_a].type
assert MyTest.class.published_variables[:variable_a]
assert_equal "map<any,any>", MyTest.class.published_variables[:variable_a].type
end

def test_variable_definition
MyTest.variable_a = ({ :a => 15 })
assert_equal ({:a => 15}), MyTest.variable_a
end

def test_type_full_specification
assert_equal "map<string,map<list<any>,map<any,any>>>", MyTest.class.published_variables[:complex].type

end
end

0 comments on commit 6ac5fdc

Please sign in to comment.