Class: NsOptions::Helper::Advisor
- Inherits:
-
Object
- Object
- NsOptions::Helper::Advisor
- Defined in:
- lib/ns-options/helper/advisor.rb
Instance Attribute Summary collapse
-
#namespace ⇒ Object
Returns the value of attribute namespace.
Instance Method Summary collapse
- #bad_method_message(kind, name) ⇒ Object
- #bad_methods ⇒ Object
- #duplicate_message(name) ⇒ Object
-
#initialize(namespace) ⇒ Advisor
constructor
A new instance of Advisor.
- #is_already_defined?(name) ⇒ Boolean
-
#is_this_namespace_ok?(name, from = nil) ⇒ Boolean
root namespace advisor.
-
#is_this_ok?(kind, name, from) ⇒ Boolean
helper methods.
- #is_this_option_ok?(name, from = nil) ⇒ Boolean
-
#is_this_sub_namespace_ok?(name, from = nil) ⇒ Boolean
sub-namespace / namespace-option advisors.
- #not_recommended_method_message(kind, name) ⇒ Object
- #not_recommended_methods ⇒ Object
Constructor Details
#initialize(namespace) ⇒ Advisor
Returns a new instance of Advisor.
9 10 11 |
# File 'lib/ns-options/helper/advisor.rb', line 9 def initialize(namespace) self.namespace = namespace end |
Instance Attribute Details
#namespace ⇒ Object
Returns the value of attribute namespace.
7 8 9 |
# File 'lib/ns-options/helper/advisor.rb', line 7 def namespace @namespace end |
Instance Method Details
#bad_method_message(kind, name) ⇒ Object
67 68 69 70 71 |
# File 'lib/ns-options/helper/advisor.rb', line 67 def (kind, name) [ "The #{kind} '#{name}' overwrites a namespace method that NsOptions depends on.", "Please choose a different name for your #{kind}." ].join(" ") end |
#bad_methods ⇒ Object
59 60 61 |
# File 'lib/ns-options/helper/advisor.rb', line 59 def bad_methods @bad_methods ||= [ :option, :namespace, :define, :options ] end |
#duplicate_message(name) ⇒ Object
73 74 75 76 77 |
# File 'lib/ns-options/helper/advisor.rb', line 73 def (name) [ "WARNING! '#{name}' has already been defined and will be overwritten.", "It's likely that it will not behave as expected." ].join(" ") end |
#is_already_defined?(name) ⇒ Boolean
54 55 56 57 |
# File 'lib/ns-options/helper/advisor.rb', line 54 def is_already_defined?(name) self.namespace..is_defined?(name) || self.namespace..is_namespace_defined?(name) end |
#is_this_namespace_ok?(name, from = nil) ⇒ Boolean
root namespace advisor
15 16 17 18 19 20 21 22 23 |
# File 'lib/ns-options/helper/advisor.rb', line 15 def is_this_namespace_ok?(name, from = nil) if [:options].include?(name.to_sym) puts self.('namespace', name) else return true end puts "From: #{(from || caller).first}" false end |
#is_this_ok?(kind, name, from) ⇒ Boolean
helper methods
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/ns-options/helper/advisor.rb', line 37 def is_this_ok?(kind, name, from) display = kind.to_s if self.bad_methods.include?(name.to_sym) = self.(display, name) exception = NsOptions::Errors::InvalidName.new(, from) raise(exception) elsif self.is_already_defined?(name) puts self.(name) elsif self.not_recommended_methods.include?(name.to_sym) puts self.(display, name) else return true end puts "From: #{from.first}" false end |
#is_this_option_ok?(name, from = nil) ⇒ Boolean
31 32 33 |
# File 'lib/ns-options/helper/advisor.rb', line 31 def is_this_option_ok?(name, from = nil) self.is_this_ok?(:option, name, (from || caller)) end |
#is_this_sub_namespace_ok?(name, from = nil) ⇒ Boolean
sub-namespace / namespace-option advisors
27 28 29 |
# File 'lib/ns-options/helper/advisor.rb', line 27 def is_this_sub_namespace_ok?(name, from = nil) self.is_this_ok?(:'sub-namespace', name, (from || caller)) end |
#not_recommended_method_message(kind, name) ⇒ Object
79 80 81 82 83 |
# File 'lib/ns-options/helper/advisor.rb', line 79 def (kind, name) [ "WARNING! The #{kind} '#{name}' overwrites a method NsOptions depends on.", "This will limit some of the functionality of NsOptions." ].join(" ") end |