Class: Yandex::Webmaster::Api::Attributes::WriterBuilder

Inherits:
AccessorBuilder show all
Defined in:
lib/yandex-webmaster/api/attributes/writer_builder.rb

Instance Attribute Summary

Attributes inherited from AccessorBuilder

#attribute_name, #object, #options, #type

Instance Method Summary collapse

Methods inherited from AccessorBuilder

#define_aliases, #initialize, #instance_variable_name, #method_name_from_options, #method_visibility, #method_visibility_from_options

Constructor Details

This class inherits a constructor from Yandex::Webmaster::Api::Attributes::AccessorBuilder

Instance Method Details

#accessorObject



11
12
13
# File 'lib/yandex-webmaster/api/attributes/writer_builder.rb', line 11

def accessor
  :writer
end

#define_methodObject



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/yandex-webmaster/api/attributes/writer_builder.rb', line 19

def define_method
  unless self.object.method_defined?(self.method_name)
    self.object.class_eval(<<-EOS, __FILE__, __LINE__ + 1)              
      def #{self.method_name}(value)
        value = #{type}.respond_to?(:typecast) ? #{type}.typecast(value) : #{type}.new(value)
        instance_variable_set(:#{instance_variable_name.to_s}, value)
      end
    EOS

    self.object.send self.method_visibility, self.method_name
    self
  end        
end

#method_nameObject



15
16
17
# File 'lib/yandex-webmaster/api/attributes/writer_builder.rb', line 15

def method_name
  self.method_name_from_options || "#{self.attribute_name}="
end