You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by "Michal Fojtik (JIRA)" <ji...@apache.org> on 2013/04/10 12:16:16 UTC

[jira] [Comment Edited] (DTACLOUD-507) Possible conflict of Deltacloud model classes with Rails classes

    [ https://issues.apache.org/jira/browse/DTACLOUD-507?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13627648#comment-13627648 ] 

Michal Fojtik edited comment on DTACLOUD-507 at 4/10/13 10:16 AM:
------------------------------------------------------------------

Hi,

I think I solved this problem partially, however I still don't understand how Rails deal with these namespacing conflicts.
So first, here is the patch:

 ~/code/wingedmonkey › git diff config/initializers/deltacloud_core.rb
diff --git a/config/initializers/deltacloud_core.rb b/config/initializers/deltacloud_core.rb
index b9a37ed..38af64d 100644
--- a/config/initializers/deltacloud_core.rb
+++ b/config/initializers/deltacloud_core.rb
@@ -14,6 +14,13 @@ Deltacloud::configure do |server|
   server.root_url '/api'
   server.version Deltacloud::API_VERSION
   server.klass 'Deltacloud::API'
+  server.default_driver :mock
 end
 
-Deltacloud[:deltacloud].require!
+Deltacloud[:deltacloud].require!(:mock_initialize => true)
+
+# FIXME: This hack is needed to prevent Rails from loading wrong Class for the
+#        Provider model.
+#        Rails should be a bit more smarter about dealing with Ruby namespaces :-)
+#
+require_relative './../../app/models/provider'

^^ This will actually let you in into Login screen without problems. After you choose the MockProvider, I get this error:

LoadError (Expected /home/mfojtik/code/wingedmonkey/app/models/provider.rb to define Provider):
  app/controllers/providers_controller.rb:14:in `<top (required)>'

Which is what I don't understand :-) First, because now it should use the correct class. Second the error is not really descriptive,
so I can't debug this....

So possible solutions:

1) Rename 'Provider' to something else... Like CloudProvider or something in WingedMonkey
2) Wrap **all** models to WingedMonkey module (so instead of 'class Provider' you will have 'class WingedMonkey::Provider')
3) Rename 'Provider' model in Deltacloud (but this will require a lot of refactoring....)

I like the option 2), mostly because now you are 'polluting' the 'global' namespace in Ruby (all WM models are not namespaced, which means the 'Provider' model is on the same level as 'Kernel' class :)
                
      was (Author: mfojtik):
    Hi,

I think I solved this problem partially, however I still don't understand how Rails deal with these namespacing conflicts.
So first, here is the patch:

 ~/code/wingedmonkey › git diff config/initializers/deltacloud_core.rb
diff --git a/config/initializers/deltacloud_core.rb b/config/initializers/deltacloud_core.rb
index b9a37ed..38af64d 100644
--- a/config/initializers/deltacloud_core.rb
+++ b/config/initializers/deltacloud_core.rb
@@ -14,6 +14,13 @@ Deltacloud::configure do |server|
   server.root_url '/api'
   server.version Deltacloud::API_VERSION
   server.klass 'Deltacloud::API'
+  server.default_driver :mock
 end
 
-Deltacloud[:deltacloud].require!
+Deltacloud[:deltacloud].require!(:mock_initialize => true)
+
+# FIXME: This hack is needed to prevent Rails from loading wrong Class for the
+#        Provider model.
+#        Rails should be a bit more smarter about dealing with Ruby namespaces :-)
+#
+require_relative './../../app/models/provider'

^^ This will actually let you in into Login screen without problems. After you choose the MockProvider, I get this error:

LoadError (Expected /home/mfojtik/code/wingedmonkey/app/models/provider.rb to define Provider):
  app/controllers/providers_controller.rb:14:in `<top (required)>'

Which is what I don't understand :-) First, because now it should use the correct class. Second the error is not really descriptive,
so I can't debug this....

So possible solutions:

1) Rename 'Provider' to something else... Like CloudProvider or something in WingedMonkey
2) Wrap **all** models to WingedMonkey module (so instead of 'class Provider' you will have 'class WingedMonkey' provider)
3) Rename 'Provider' model in Deltacloud (but this will require a lot of refactoring....)

I like the option 2), mostly because now you are 'polluting' the 'global' namespace in Ruby (all WM models are not namespaced, which means the 'Provider' model is on the same level as 'Kernel' class :)
                  
> Possible conflict of Deltacloud model classes with Rails classes
> ----------------------------------------------------------------
>
>                 Key: DTACLOUD-507
>                 URL: https://issues.apache.org/jira/browse/DTACLOUD-507
>             Project: DeltaCloud
>          Issue Type: Bug
>            Reporter: Michal Fojtik
>            Assignee: Michal Fojtik
>            Priority: Blocker
>
> Right now the models we have in Deltacloud does not have any namespece.
> Models like 'Provider' or 'Image' exists in the 'global' namespace.
> This could be a problem when you have an Rails app that define models with
> same name (Provider for example).
> I think this is a good argument to make *all* Deltacloud models live in the
> Deltacloud namespace (Deltacloud::Provider).

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira