Class: Yast::TypeRepositoryClass
- Inherits:
-
Module
- Object
- Module
- Yast::TypeRepositoryClass
- Defined in:
- ../../src/modules/TypeRepository.rb
Instance Method Summary (collapse)
-
- (Object) enum_validator(values, value)
Generic enumerated type validator.
-
- (Object) is_a(value, type)
Validate, that the given value is of given type.
-
- (Object) is_string(s)
Check, if s is a string.
-
- (Object) IsEmpty(value)
Checks if given argument is empty.
- - (Object) main
-
- (Object) regex_validator(regex, value)
Generic regular expression validator.
-
- (Object) TypeRepository
Constructor, defines the known types.
Instance Method Details
- (Object) enum_validator(values, value)
Generic enumerated type validator.
@param [Array] values a list of possible values @param [String] value the value to be matched @return true if successful
135 136 137 138 |
# File '../../src/modules/TypeRepository.rb', line 135 def enum_validator(values, value) values = deep_copy(values) Builtins.contains(values, value) end |
- (Object) is_a(value, type)
Validate, that the given value is of given type.
52 53 54 55 56 57 58 59 60 61 |
# File '../../src/modules/TypeRepository.rb', line 52 def is_a(value, type) value = deep_copy(value) validator = Ops.get(@types, type) if !validator.nil? return validator.call(value) else Builtins.y2error("Request to validate unknown type %1", type) end false end |
- (Object) is_string(s)
Check, if s is a string.
67 68 69 70 |
# File '../../src/modules/TypeRepository.rb', line 67 def is_string(s) s = deep_copy(s) Ops.is_string?(s) end |
- (Object) IsEmpty(value)
Checks if given argument is empty.
For other types than string, list, map returns true when value is nil. For list and map checks if value is nil or doesn't contain any item ( [] resp $[] ). For string checks if value is nil or equal to string without any chars (“”).
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File '../../src/modules/TypeRepository.rb', line 102 def IsEmpty(value) value = deep_copy(value) return true if value.nil? ret = false ret = Builtins.isempty(Convert.to_string(value)) if Ops.is_string?(value) ret = Builtins.isempty(Convert.to_list(value)) if Ops.is_list?(value) ret = Builtins.isempty(Convert.to_map(value)) if Ops.is_map?(value) ret = Builtins.size(Convert.to_term(value)) == 0 if Ops.is_term?(value) ret end |
- (Object) main
35 36 37 38 39 40 41 42 43 44 45 |
# File '../../src/modules/TypeRepository.rb', line 35 def main Yast.import "Address" Yast.import "Hostname" Yast.import "IP" Yast.import "Netmask" Yast.import "URL" # Map of known types, empty initially @types = {} TypeRepository() end |
- (Object) regex_validator(regex, value)
Generic regular expression validator.
@param [String] regex the regular expression to be matched @param [String] value the value to be matched @return true if successful
126 127 128 |
# File '../../src/modules/TypeRepository.rb', line 126 def regex_validator(regex, value) Builtins.regexpmatch(value, regex) end |
- (Object) TypeRepository
Constructor, defines the known types.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File '../../src/modules/TypeRepository.rb', line 73 def TypeRepository @types = { "ip" => fun_ref(IP.method(:Check), "boolean (string)"), "ip4" => fun_ref(IP.method(:Check4), "boolean (string)"), "ip6" => fun_ref(IP.method(:Check6), "boolean (string)"), "netmask" => fun_ref(Netmask.method(:Check), "boolean (string)"), "netmask4" => fun_ref(Netmask.method(:Check4), "boolean (string)"), "netmask6" => fun_ref(Netmask.method(:Check6), "boolean (string)"), "host" => fun_ref(Address.method(:Check), "boolean (string)"), "host4" => fun_ref(Address.method(:Check4), "boolean (string)"), "host6" => fun_ref(Address.method(:Check6), "boolean (string)"), "hostname" => fun_ref(Hostname.method(:Check), "boolean (string)"), "fullhostname" => fun_ref(Hostname.method(:CheckFQ), "boolean (string)"), "domain" => fun_ref( Hostname.method(:CheckDomain), "boolean (string)" ), "url" => fun_ref(URL.method(:Check), "boolean (string)"), "string" => fun_ref(method(:is_string), "boolean (any)") } nil end |