Class: Yandex::Webmaster::Api::AttributesBuilder
- Defined in:
- lib/yandex-webmaster/api/attributes_builder.rb
Instance Attribute Summary collapse
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #attr(*args) ⇒ Object
-
#initialize(object, options, &block) ⇒ AttributesBuilder
constructor
A new instance of AttributesBuilder.
Constructor Details
#initialize(object, options, &block) ⇒ AttributesBuilder
Returns a new instance of AttributesBuilder.
9 10 11 12 13 14 15 16 |
# File 'lib/yandex-webmaster/api/attributes_builder.rb', line 9 def initialize(object, , &block) @object = object @options = raise ArgumentError.new('Missing options[:as] value' ) if @options[:as].blank? self.instance_eval(&block) end |
Instance Attribute Details
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
7 8 9 |
# File 'lib/yandex-webmaster/api/attributes_builder.rb', line 7 def klass @klass end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/yandex-webmaster/api/attributes_builder.rb', line 7 def @options end |
Class Method Details
.cast_type(constant) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/yandex-webmaster/api/attributes_builder.rb', line 34 def self.cast_type(constant) return constant if constant.is_a?(Class) && constant < Yandex::Webmaster::Api::Attributes::Types::Base string = constant.to_s string = string.camelize if (string =~ /\w_\w/ || string[0].downcase == string[0]) begin if Yandex::Webmaster::Api::Attributes::Types.const_defined?(string) return Yandex::Webmaster::Api::Attributes::Types.const_get(string) elsif Module.const_defined?(string) return Module.const_get(string) else return nil end rescue return constant end end |
Instance Method Details
#attr(*args) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/yandex-webmaster/api/attributes_builder.rb', line 18 def attr(*args) = args. type = .delete(:type) || args[1] attribute_name = args[0].to_s casted_type = self.class.cast_type(type) self.class.const_missing(type.to_s) if casted_type.blank? reader_builder = Yandex::Webmaster::Api::Attributes::ReaderBuilder.new(@object, attribute_name, casted_type, ) writer_builder = Yandex::Webmaster::Api::Attributes::WriterBuilder.new(@object, attribute_name, casted_type, ) self.add_attribute(attribute_name, reader_builder, writer_builder) reader_builder.define_method.define_aliases writer_builder.define_method.define_aliases end |