user2006506
user2006506

Reputation: 119

uninitialized constant (NameError) Ruby

I am fairly new to ruby and trying to write a gem file but the following error occurs.I have updated bundler and the relevant gems as was suggested in other posts. Developing with

Traceback (most recent call last):
    15: from /usr/local/bin/vcdm:23:in `<main>'
    14: from /usr/local/bin/vcdm:23:in `load'
    13: from /var/lib/gems/2.5.0/gems/vcdm-0.1.2/bin/vcdm:4:in `<top (required)>'
    12: from /usr/local/lib/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:72:in `require'
    11: from /usr/local/lib/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:72:in `require'
    10: from /var/lib/gems/2.5.0/gems/vcdm-0.1.2/lib/vcdm.rb:2:in `<top (required)>'
     9: from /usr/local/lib/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:72:in `require'
     8: from /usr/local/lib/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:72:in `require'
     7: from /var/lib/gems/2.5.0/gems/vcdm-0.1.2/lib/vcdm/command.rb:1:in `<top (required)>'
     6: from /var/lib/gems/2.5.0/gems/vcdm-0.1.2/lib/vcdm/command.rb:4:in `<module:Vcdm>'
     5: from /var/lib/gems/2.5.0/gems/vcdm-0.1.2/lib/vcdm/command.rb:4:in `glob'
     4: from /usr/local/lib/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:92:in `require'
     3: from /usr/local/lib/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:92:in `require'
     2: from /var/lib/gems/2.5.0/gems/vcdm-0.1.2/lib/vcdm/commands/hostfile.rb:4:in `<top (required)>'
     1: from /var/lib/gems/2.5.0/gems/vcdm-0.1.2/lib/vcdm/commands/hostfile.rb:5:in `<module:Vcdm>'
/var/lib/gems/2.5.0/gems/vcdm-0.1.2/lib/vcdm/commands/hostfile.rb:14:in `<class:HostfileCommand>': uninitialized constant Vcdm::HostfileCommand::CommandOption (NameError)

These are my code what I am tring to execute command_option.rb

module Vcdm

  class CommandOption
    attr_reader :name, :type, :description

    def initialize(name, type, description)
      @name = name
      @type = type
      @description = description
    end

  end

end

hostfile.rb

require 'vcdm/command_interface'

module Vcdm
  class HostfileCommand
    as = CommandOption.new("--path STRING", String, "custom hosts path")

    IS_PUBLIC_COMMAND = true
    SYNTAX = 'vcdm hostfile'
    SUMMARY = 'adds the ingress url to the users hostfile'
    DESCRIPTION = ""
    EXAMPLE = "vcdm hostfile --path=/mnt/c/Windows/System32/drivers/etc/hosts"
    EXAMPLE_DESCRIPTION = ""
    implements CommandInterface

  end

end

command_interface.rb

require 'class_interface'

class CommandInterface
  IS_PUBLIC_COMMAND = true | false
  SYNTAX = String
  SUMMARY = String
  DESCRIPTION = String
  EXAMPLE = String
  EXAMPLE_DESCRIPTION = String
  OPTIONS = Array

  def initialize
  end

  def execute(args, options)
  end

end

Is there anything wrong?

Upvotes: 0

Views: 2643

Answers (2)

spickermann
spickermann

Reputation: 106802

It feels to me like you are missing a

require 'vcdm/command_option'

in your hostfile.rb. Just add that line to the top of that file.

Upvotes: 1

Fernand
Fernand

Reputation: 1333

try putting this in 'config/application.rb'

config.eager_load_paths << "#{Rails.root}/lib"

and then in 'hostfile.rb'

require 'vcdm/command_interface'

module Vcdm
  include CommandOption
  class HostfileCommand
  ...

Upvotes: 0

Related Questions