Permalink
Browse files

Prettify the example with a procedure ;)

  • Loading branch information...
1 parent 6e431ef commit 1ad2b714d5b99dd299bb05969a5c612145d31c9d @errordeveloper committed Apr 13, 2012
Showing with 20 additions and 10 deletions.
  1. +20 −10 examples/server.rb
View
@@ -9,19 +9,29 @@ def initialize
@ep = Cf::LocalEndpoint.new
# Add a few basic endpoints
@ep.addResource(Cf::HelloWorldResource.new)
- @ep.addResource(Cf::ZurichWeatherResource.new)
+ # This resource generates an errror if there
+ # is no Internet connection
+ #@ep.addResource(Cf::ZurichWeatherResource.new)
# This is somewhat of a hack, but it works!
# (see: `lib/modules/basic_resource`)
- @my = Text::Plain.new('helloWorld.rb')
- @my.setTitle('Hello Californium/JRuby!')
- @my.setResourceType('HelloWorldDisplayer')
- @ep.addResource(@my)
-
- @json = Application::JSON.new('test.json')
- @json.setTitle('{"hello":"json"}')
- @json.setResourceType('testJSON')
- @ep.addResource(@json)
+
+ @my = {};
+
+ append = Proc.new { |with,handle,title,type|
+ m = @my[handle] = with.new(handle)
+ m.setTitle(title)
+ m.setResourceType(type)
+ @ep.addResource(m)
+ }
+
+ append.call(Text::Plain, 'hello.rb',
+ 'Hello, Californium + JRuby!', 'Test1')
+
+ append.call(Application::JSON, 'hello.json',
+ '{"kind_of": "JSON"}', 'Test2')
+
+ # p @my
end
end

0 comments on commit 1ad2b71

Please sign in to comment.