Class: Whois::SafeRecord
- Inherits:
- BasicObject
- Defined in:
- lib/whois/safe_record.rb
Instance Attribute Summary collapse
-
#record ⇒ Object
(also: #target)
readonly
Returns the value of attribute record.
Class Method Summary collapse
- .define_method_method(method) ⇒ Object private
- .define_property_method(method) ⇒ Object private
- .define_question_method(method) ⇒ Object private
Instance Method Summary collapse
-
#admin_contact ⇒ Whois::Parser::Contact?
Shortcut for
#admin_contacts.first. -
#contacts ⇒ Array<Whois::Parser::Contact>
Collects and returns all the contacts.
-
#initialize(record) ⇒ SafeRecord
constructor
A new instance of SafeRecord.
-
#parser ⇒ Whois::Parser
Lazy-loads and returns the parser proxy for current record.
-
#properties ⇒ { Symbol => Object }
Returns a Hash containing all supported properties for this record along with corresponding values.
-
#registrant_contact ⇒ Whois::Parser::Contact?
Shortcut for
#registrant_contacts.first. -
#respond_to?(*args) ⇒ Boolean
Checks if this class respond to given method.
-
#technical_contact ⇒ Whois::Parser::Contact?
Shortcut for
#technical_contacts.first.
Constructor Details
#initialize(record) ⇒ SafeRecord
54 55 56 |
# File 'lib/whois/safe_record.rb', line 54 def initialize(record) @record = record end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object (private)
Delegates any missing method to Record.
165 166 167 |
# File 'lib/whois/safe_record.rb', line 165 def method_missing(method, *args, &block) target.send(method, *args, &block) end |
Instance Attribute Details
#record ⇒ Object (readonly) Also known as: target
Returns the value of attribute record.
52 53 54 |
# File 'lib/whois/safe_record.rb', line 52 def record @record end |
Class Method Details
.define_method_method(method) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
18 19 20 21 22 23 24 25 26 |
# File 'lib/whois/safe_record.rb', line 18 def self.define_method_method(method) class_eval " def \#{method}(*args, &block)\n if parser.respond_to?(:\#{method})\n parser.\#{method}(*args, &block)\n end\n end\n RUBY\nend\n", __FILE__, __LINE__ + 1 |
.define_property_method(method) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
7 8 9 10 11 12 13 14 15 |
# File 'lib/whois/safe_record.rb', line 7 def self.define_property_method(method) class_eval " def \#{method}(*args, &block)\n if property_any_supported?(:\#{method})\n parser.\#{method}(*args, &block)\n end\n end\n RUBY\nend\n", __FILE__, __LINE__ + 1 |
.define_question_method(method) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
29 30 31 32 33 34 35 36 37 |
# File 'lib/whois/safe_record.rb', line 29 def self.define_question_method(method) return if method.to_s.end_with?("?") class_eval " def \#{method}?\n !\#{method}.nil?\n end\n RUBY\nend\n", __FILE__, __LINE__ + 1 |
Instance Method Details
#admin_contact ⇒ Whois::Parser::Contact?
Shortcut for #admin_contacts.first.
114 115 116 117 118 |
# File 'lib/whois/safe_record.rb', line 114 def admin_contact if property_any_supported?(:admin_contacts) admin_contacts.first end end |
#contacts ⇒ Array<Whois::Parser::Contact>
Collects and returns all the contacts.
139 140 141 |
# File 'lib/whois/safe_record.rb', line 139 def contacts parser.contacts end |
#parser ⇒ Whois::Parser
Lazy-loads and returns the parser proxy for current record.
76 77 78 |
# File 'lib/whois/safe_record.rb', line 76 def parser @parser ||= Parser.new(record) end |
#properties ⇒ { Symbol => Object }
Returns a Hash containing all supported properties for this record along with corresponding values.
84 85 86 87 88 89 90 |
# File 'lib/whois/safe_record.rb', line 84 def properties hash = {} Parser::PROPERTIES.each do |property| hash[property] = __send__(property) end hash end |
#registrant_contact ⇒ Whois::Parser::Contact?
Shortcut for #registrant_contacts.first.
100 101 102 103 104 |
# File 'lib/whois/safe_record.rb', line 100 def registrant_contact if property_any_supported?(:registrant_contacts) registrant_contacts.first end end |
#respond_to?(*args) ⇒ Boolean
Checks if this class respond to given method.
Overrides the default implementation to add support for Parser::PROPERTIES and Parser::METHODS.
68 69 70 |
# File 'lib/whois/safe_record.rb', line 68 def respond_to?(*args) respond_to_parser_method?(args.first) || target.respond_to?(*args) end |
#technical_contact ⇒ Whois::Parser::Contact?
Shortcut for #technical_contacts.first.
128 129 130 131 132 |
# File 'lib/whois/safe_record.rb', line 128 def technical_contact if property_any_supported?(:technical_contacts) technical_contacts.first end end |