Class: Wrong::Config
- Inherits:
-
Hash
show all
- Defined in:
- lib/wrong/config.rb,
lib/wrong/adapters/rspec.rb,
lib/wrong/adapters/rspec.rb
Defined Under Namespace
Classes: ConfigError
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(string = nil) ⇒ Config
Returns a new instance of Config.
38
39
40
41
42
43
|
# File 'lib/wrong/config.rb', line 38
def initialize(string = nil)
self[:aliases] = {:assert => [:assert], :deny => [:deny]}
if string
instance_eval string.gsub(/^(.*=)/, "self.\\1")
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, value = true) ⇒ Object
45
46
47
48
49
50
51
|
# File 'lib/wrong/config.rb', line 45
def method_missing(name, value = true)
name = name.to_s
if name =~ /=$/
name.gsub!(/=$/, '')
end
self[name.to_sym] = value
end
|
Class Method Details
.read_here_or_higher(file, dir = ".") ⇒ Object
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/wrong/config.rb', line 27
def self.read_here_or_higher(file, dir = ".")
File.read "#{dir}/#{file}"
rescue Errno::ENOENT, Errno::EACCES => e
parent = "#{dir}/..".gsub(/^(\.\/)*/, '')
if File.expand_path(dir) == File.expand_path(parent)
raise Errno::ENOENT, "couldn't find #{file}"
end
read_here_or_higher(file, parent)
end
|
Instance Method Details
#alias_assert(method_name, options = {}) ⇒ Object
59
60
61
|
# File 'lib/wrong/config.rb', line 59
def alias_assert(method_name, options = {})
alias_assert_or_deny(:assert, method_name, options)
end
|
#alias_assert_or_deny(valence, extra_name, options = {}) ⇒ Object
53
54
55
56
57
|
# File 'lib/wrong/config.rb', line 53
def alias_assert_or_deny(valence, , options)
Wrong::Assert.send(:alias_method, , valence)
new_method_name = .to_sym
self[:aliases][valence] << new_method_name unless self[:aliases][valence].include?(new_method_name)
end
|
#alias_assert_or_deny_original ⇒ Object
46
47
48
49
50
|
# File 'lib/wrong/adapters/rspec.rb', line 46
def alias_assert_or_deny(valence, , options)
Wrong::Assert.send(:alias_method, , valence)
new_method_name = .to_sym
self[:aliases][valence] << new_method_name unless self[:aliases][valence].include?(new_method_name)
end
|
#alias_deny(method_name, options = {}) ⇒ Object
63
64
65
|
# File 'lib/wrong/config.rb', line 63
def alias_deny(method_name, options = {})
alias_assert_or_deny(:deny, method_name, options)
end
|
#assert_method_names ⇒ Object
67
68
69
|
# File 'lib/wrong/config.rb', line 67
def assert_method_names
self[:aliases][:assert]
end
|
#deny_method_names ⇒ Object
71
72
73
|
# File 'lib/wrong/config.rb', line 71
def deny_method_names
self[:aliases][:deny]
end
|
#hidden_methods ⇒ Object
75
76
77
|
# File 'lib/wrong/config.rb', line 75
def hidden_methods
assert_method_names + deny_method_names + [:eventually]
end
|