2013-02-23 3 views
1

간단한 질문;외부 정적 클래스에서 Capistrano 메서드에 액세스하는 방법?

namespace :mycompany do 
    class SomeClass 
     def self.some_static_method() 
      mylog = capture("some_command") 
     end 
    end 
end 
:이처럼 클래스의 방법을 사용하는 경우, 그러나

namespace :mycompany do 
    def some_function() 
     mylog = capture("some_command") 
    end 

    desc <<-DESC 
     some task description 
    DESC 
    task :some_task do 
     mylog = capture("some_command") 
    end 
end 

: 그래서 카피 스트라 노에서 내 deploy.rb 스크립트는 내가 쉽게 캡처 기능을 사용할 수있는 곳처럼 보인다

비참하게 실패합니다 :

/config/deploy.rb:120:in `some_static_method': undefined method `capture' for #<Class:0x000000026234f8>::SomeClass (NameError) 

어떻게해야합니까?

module Capistrano 
    class Configuration 
     module Actions 
      module Inspect 

       # Executes the given command on the first server targetted by the 
       # current task, collects it's stdout into a string, and returns the 
       # string. The command is invoked via #invoke_command. 
       def capture(command, options={}) 
        ... 

답변

1

누군가가 이 방법 포함 사용하도록 제안 :이 방법은 (카피 스트라 노 소스) 여기 안에 뭐가 :(정적 될 것 같지 않습니다

namespace :mycompany do 
    class SomeClass 
     include Capistrano::Configuration::Actions::Inspect 

     def self.some_static_method() 
      mylog = self.new.capture("some_command") 
     end 
    end 
end 

을하지만 그 내부 오류로 인해 실패 캡처 :

/var/lib/gems/1.9.1/gems/capistrano-2.14.2/lib/capistrano/configuration/actions/inspect.rb:34:in `capture': undefined local variable or method `sudo' for #<#<Class:0x00000001cbb8e8>::SomeClass:0x000000027034e0> (NameError) 

는 그래서 단순히 한 일은 매개 변수로 (해키하지만 작동) 인스턴스를 통과입니다

.
namespace :mycompany do 
    def some_function() 
     SomeClass.some_static_method(self) 
    end 

    class SomeClass 
     def self.some_static_method(capistrano) 
      mylog = capistrano.capture("some_command") 
     end 
    end 
end 

FML

관련 문제