Class: NsOptions::NamespaceAdvisor

Inherits:
Object
  • Object
show all
Defined in:
lib/ns-options/namespace_advisor.rb

Instance Method Summary collapse

Constructor Details

#initialize(ns_data, name, kind) ⇒ NamespaceAdvisor

Returns a new instance of NamespaceAdvisor.



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/ns-options/namespace_advisor.rb', line 5

def initialize(ns_data, name, kind)
  @ns_data = ns_data
  @name = name

  @msg = if not_recommended?
    "WARNING: Defining #{kind} with the name `#{@name}' overwrites a method"\
    " NsOptions depends on.  It may cause NsOptions to behave oddly and"\
    " is not recommended."
  elsif duplicate?
    "WARNING: `#{@name}' has already been defined and is being overwritten."
  end
end

Instance Method Details

#duplicate?Boolean

Returns:



27
# File 'lib/ns-options/namespace_advisor.rb', line 27

def duplicate?; @ns_data.has_option?(@name) || @ns_data.has_namespace?(@name); end

#not_recommended?Boolean

Returns:



26
# File 'lib/ns-options/namespace_advisor.rb', line 26

def not_recommended?; not_recommended_names.include?(@name.to_sym); end


29
30
31
# File 'lib/ns-options/namespace_advisor.rb', line 29

def not_recommended_names
  NsOptions::Namespace.instance_methods(false).map(&:to_sym)
end

#run(io, from_caller) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/ns-options/namespace_advisor.rb', line 18

def run(io, from_caller)
  return true if @msg.nil?

  io.puts @msg
  io.puts from_caller.first
  false
end