1
我有我創建的紅寶石寶石,我一直在使用我的rails-api應用程序。我最近加入到創業板的配置,所以我可以從我的軌道-API的應用程序,它看起來像這樣配置它:如何使我的現有ruby gem配置可用於我的rails-api應用程序?
# In rails-api app /config/initializers/my_gem.rb
MyGem::MyNamespace.configure do |config|
config.allow_custom_commands = true
end
然而,當我開始在軌服務器,我得到一個錯誤NoMethod :
/Users/me/dev/rails/api.abc/config/initializers/my_gem.rb:61:in `<top (required)>': undefined method `configure' for MyGem::MyNamespace:Module (NoMethodError)
from /Users/me/dev/rails/api.mohojo-werks/vendor/bundle/gems/activesupport-5.0.5/lib/active_support/dependencies.rb:287:in `load'
from /Users/me/dev/rails/api.mohojo-werks/vendor/bundle/gems/activesupport-5.0.5/lib/active_support/dependencies.rb:287:in `block in load'
from /Users/me/dev/rails/api.mohojo-werks/vendor/bundle/gems/activesupport-5.0.5/lib/active_support/dependencies.rb:259:in `load_dependency'
etc.
我所有的寶石測試都通過了,所以我不知道自己做錯了什麼。這裏是我的配置文件:
# /my_gem/configuration.rb
module MyGem
module MyNamespace
class Configuration
attr_accessor :allow_custom_commands
def initialize
reset
end
public
def reset
@allow_custom_commands = false
nil
end
end
end
end
# /my_gem/configure.rb
module MyGem
module MyNamespace
class << self
attr_writer :configuration
end
def self.configuration
@configuration ||= Configuration.new
end
def self.configure
yield(configuration)
end
end
end