Class: NsOptions::Namespace
- Inherits:
-
Object
- Object
- NsOptions::Namespace
show all
- Defined in:
- lib/ns-options/namespace.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#==(other_ns) ⇒ Object
-
#apply(*args, &block) ⇒ Object
-
#build_from(other_ns) ⇒ Object
-
#define(*args, &block) ⇒ Object
-
#each(*args, &block) ⇒ Object
-
#has_namespace?(name) ⇒ Boolean
-
#has_option?(name) ⇒ Boolean
-
#initialize(name, option_type_class = nil, &block) ⇒ Namespace
constructor
A new instance of Namespace.
-
#inspect(*args) ⇒ Object
-
#method_missing(meth, *args, &block) ⇒ Object
-
#namespace(name, *args, &block) ⇒ Object
(also: #ns)
-
#option(name, *args) ⇒ Object
(also: #opt)
-
#option_type_class(*args) ⇒ Object
(also: #opt_type_class)
-
#required_set? ⇒ Boolean
(also: #valid?)
-
#reset(*args, &block) ⇒ Object
-
#respond_to?(meth) ⇒ Boolean
-
#to_hash(*args, &block) ⇒ Object
Constructor Details
#initialize(name, option_type_class = nil, &block) ⇒ Namespace
Returns a new instance of Namespace.
10
11
12
13
14
|
# File 'lib/ns-options/namespace.rb', line 10
def initialize(name, option_type_class=nil, &block)
@__name__ = name
@__data__ = NamespaceData.new(self, option_type_class || Object)
@__data__.define(&block)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
50
51
52
53
54
55
|
# File 'lib/ns-options/namespace.rb', line 50
def method_missing(meth, *args, &block)
@__data__.ns_method_missing(meth, *args, &block)
rescue StandardError => exception
exception.set_backtrace(caller)
raise exception
end
|
Instance Attribute Details
#__data__ ⇒ Object
Returns the value of attribute __data__.
8
9
10
|
# File 'lib/ns-options/namespace.rb', line 8
def __data__
@__data__
end
|
#__name__ ⇒ Object
Returns the value of attribute __name__.
8
9
10
|
# File 'lib/ns-options/namespace.rb', line 8
def __name__
@__name__
end
|
Instance Method Details
#==(other_ns) ⇒ Object
57
58
59
60
61
62
63
|
# File 'lib/ns-options/namespace.rb', line 57
def ==(other_ns)
if other_ns.kind_of? Namespace
self.to_hash == other_ns.to_hash
else
super
end
end
|
#apply(*args, &block) ⇒ Object
42
|
# File 'lib/ns-options/namespace.rb', line 42
def apply(*args, &block); @__data__.apply(*args, &block); end
|
#build_from(other_ns) ⇒ Object
40
|
# File 'lib/ns-options/namespace.rb', line 40
def build_from(other_ns); @__data__.build_from(other_ns.__data__); end
|
#define(*args, &block) ⇒ Object
39
|
# File 'lib/ns-options/namespace.rb', line 39
def define(*args, &block); @__data__.define(*args, &block); end
|
#each(*args, &block) ⇒ Object
44
|
# File 'lib/ns-options/namespace.rb', line 44
def each(*args, &block); @__data__.each(*args, &block); end
|
#has_namespace?(name) ⇒ Boolean
35
|
# File 'lib/ns-options/namespace.rb', line 35
def has_namespace?(name); @__data__.has_namespace?(name); end
|
#has_option?(name) ⇒ Boolean
34
|
# File 'lib/ns-options/namespace.rb', line 34
def has_option?(name); @__data__.has_option?(name); end
|
#inspect(*args) ⇒ Object
65
66
67
68
|
# File 'lib/ns-options/namespace.rb', line 65
def inspect(*args)
inspect_details = to_hash.inspect rescue "error getting inspect details"
"#<#{self.class}:#{'0x%x' % (self.object_id << 1)}:#{@__name__} #{inspect_details}>"
end
|
#namespace(name, *args, &block) ⇒ Object
Also known as:
ns
22
23
24
25
|
# File 'lib/ns-options/namespace.rb', line 22
def namespace(name, *args, &block)
NamespaceAdvisor.new(@__data__, name, 'a namespace').run($stdout, caller)
@__data__.add_namespace(name, *args, &block)
end
|
#option(name, *args) ⇒ Object
Also known as:
opt
16
17
18
19
|
# File 'lib/ns-options/namespace.rb', line 16
def option(name, *args)
NamespaceAdvisor.new(@__data__, name, 'an option').run($stdout, caller)
@__data__.add_option(name, *args)
end
|
#option_type_class(*args) ⇒ Object
Also known as:
opt_type_class
28
29
30
31
|
# File 'lib/ns-options/namespace.rb', line 28
def option_type_class(*args)
return @__data__.option_type_class if args.empty?
@__data__.set_option_type_class(*args)
end
|
#required_set? ⇒ Boolean
Also known as:
valid?
36
|
# File 'lib/ns-options/namespace.rb', line 36
def required_set?; @__data__.required_set?; end
|
#reset(*args, &block) ⇒ Object
41
|
# File 'lib/ns-options/namespace.rb', line 41
def reset(*args, &block); @__data__.reset(*args, &block); end
|
#respond_to?(meth) ⇒ Boolean
46
47
48
|
# File 'lib/ns-options/namespace.rb', line 46
def respond_to?(meth)
@__data__.ns_respond_to?(meth) || super
end
|
#to_hash(*args, &block) ⇒ Object
43
|
# File 'lib/ns-options/namespace.rb', line 43
def to_hash(*args, &block); @__data__.to_hash(*args, &block); end
|