Class: Yandex::Webmaster::Base
- Includes:
- Authorization, Connection, Request
- Defined in:
- lib/yandex-webmaster/base.rb
Direct Known Subclasses
ApiFactory, Client, Host, Hosts::Crawling, Hosts::Sitemap, Hosts::SitemapInfo, Hosts::TopInfo, Hosts::Verification
Constant Summary
Constants included from Request
Request::METHODS, Request::METHODS_WITH_BODIES
Constants included from Connection
Connection::ACCEPT, Connection::ACCEPT_CHARSET, Connection::ALLOWED_OPTIONS, Connection::CONTENT_TYPE, Connection::USER_AGENT
Instance Attribute Summary collapse
-
#configuration ⇒ Object
Returns the value of attribute configuration.
Attributes included from Authorization
Class Method Summary collapse
Instance Method Summary collapse
- #attributes=(attributes = {}) ⇒ Object
-
#initialize(attributes = {}) ⇒ Base
constructor
A new instance of Base.
-
#method_missing(method, *args, &block) ⇒ Object
Responds to attribute query or attribute clear.
Methods included from Request
#delete_request, #get_request, #post_request, #put_request, #request
Methods included from Connection
Methods included from Authorization
#auth_code, #authenticate, #authenticated?, #authorize_url, #oauth, #token
Constructor Details
#initialize(attributes = {}) ⇒ Base
Returns a new instance of Base.
58 59 60 |
# File 'lib/yandex-webmaster/base.rb', line 58 def initialize(attributes = {}) self.attributes = attributes end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
Responds to attribute query or attribute clear
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/yandex-webmaster/base.rb', line 74 def method_missing(method, *args, &block) # :nodoc: case method.to_s when /^(.*)\?$/ return !!self.send($1.to_s) when /^clear_(.*)$/ self.send("#{$1.to_s}=", nil) else super end end |
Instance Attribute Details
#configuration ⇒ Object
Returns the value of attribute configuration.
56 57 58 |
# File 'lib/yandex-webmaster/base.rb', line 56 def configuration @configuration end |
Class Method Details
.const_missing(name) ⇒ Object
51 52 53 |
# File 'lib/yandex-webmaster/base.rb', line 51 def const_missing(name) Yandex::Webmaster::Api::AttributesBuilder.cast_type(name) || super end |
.define_attributes(options = {}, &block) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/yandex-webmaster/base.rb', line 17 def define_attributes( = {}, &block) [:as] ||= :attributes cattr_accessor [:as].to_sym class_eval(<<-EOS, __FILE__, __LINE__ + 1) @@#{[:as].to_s} ||= {} EOS unless [:inspect] == false define_method(:inspect) do inspection = self.send([:as].to_s).map { |key, value| self.inspect_attribute(key, value[:instance_variable_name]) }.compact.join(', ') "#<#{self.class} #{inspection}>" end define_method(:inspect_attribute) do |attribute_name, instance_variable_name| value = instance_variable_get(instance_variable_name.to_s) if value.is_a?(String) && value.length > 50 "#{attribute_name.to_s}[#{value.size}]: " + "#{value[0..50]}...".inspect elsif value.is_a?(Array) && value.length > 5 "#{attribute_name.to_s}[#{value.size}]: " + "#{value[0..5]}...".inspect else "#{attribute_name.to_s}: " + value.inspect end end end Yandex::Webmaster::Api::AttributesBuilder.new(self, , &block) end |
Instance Method Details
#attributes=(attributes = {}) ⇒ Object
62 63 64 65 66 |
# File 'lib/yandex-webmaster/base.rb', line 62 def attributes=(attributes = {}) attributes.each do |attr,value| self.send("#{attr}=", value) if self.respond_to?("#{attr}=") end end |