2013-08-01 37 views
2

我有以下設置:安裝中的其他導軌申請創業板的包

一個通過這個應用程序開發者軌4.0.0應用=>我的主應用

可以創建寶石骷髏

現在I' d喜歡創建gem骨架源代碼並通過rails master應用程序中的調用運行gem Gemfile的bundle安裝:

class MyClass 

    # this works 
    def create_gem_skeleton 
    path = "path-to-gem-skeleton-outside-the-rails-master-app" 
    FileUtils.mkdir_p(path) 
    `cd #{path} && bundle gem my-new-gem` 
    end 

    # this method gets called, after I created the gem skeleton and manipulated it a bit with my preferences 
    def my_method 
    path = "path-to-gem-skeleton-outside-the-rails-master-app" 
    exec `cd #{path} && bundle install` # does not work, installs always the rails master bundle inside my rails master application, never touches the new gem-skeleton 
    system `cd #{path} && bundle install` # =||= .. same here 
    `cd #{path} && bundle install`  # =||= .. same here 

    end 

end 

Any身體一個想法如何我可以在我的rails master應用程序中運行這樣的「bundle install」調用,將bundle安裝在新的gem-skeleton中,而不是觸摸rails套件?

我使用rails 4.0.0和ruby 2.0.0-p195

謝謝!

回答

6

你應該在傳遞給Bundler.with_clean_env的塊中包裹反引號調用。這將確保它不會拿起您的應用程序的Gemfile中:

Bundler.with_clean_env { `cd #{path} && bundle install` } 

有關詳細信息,請參閱bundle-exec man page

+1

似乎工作完美!非常感謝!我已經閱讀了bundle-exec手冊頁,但還不夠完美:)。 – Mattherick

+0

我正在調試並正在處理該問題%&! 4個小時,這拯救了我的生活!謝謝! –

0

難道是一個很好的解決方案,爲您打造具有相關性的寶石?

自身將不包含任何特定的代碼寶石,但是每次你需要一個新的依賴,你只需要修改其gemspec,和其他應用程序只需運行bundle update將更新您的寶石,並安裝了新的依賴。

+0

不,這是不可能的。 – Mattherick

0

我認爲你必須觸摸你的主包,至少包括你的寶石。當你捆綁你的主應用程序時,所有的gem依賴項都會被安裝並鎖定到你的主Gemfile.lock中以進行依賴關係解析。

+0

新的創業板並沒有被納入主應用程序..它是一個獨立的創業板。主應用程序只管理創建。主應用程序 - >獨立導軌應用程序,新寶石 - >獨立的寶石,其中一個其他寶石被添加 - >捆綁安裝.. – Mattherick