module Avro::Builder::DslAttributes::ClassMethods

Public Instance Methods

add_attribute_name(name) click to toggle source
# File lib/avro/builder/dsl_attributes.rb, line 61
def add_attribute_name(name)
  dsl_attribute_names << name
  add_option_name(name)
end
dsl_attribute(name, &block) click to toggle source

If a block is specified then it is used to define the combined getter/setter method for the DSL attribute.

# File lib/avro/builder/dsl_attributes.rb, line 27
def dsl_attribute(name, &block)
  if block_given?
    add_attribute_name(name)
    define_method(name, &block)
    alias_writer(name)
  else
    dsl_attributes(name)
  end
end
dsl_attribute_alias(new_name, old_name) click to toggle source
# File lib/avro/builder/dsl_attributes.rb, line 46
def dsl_attribute_alias(new_name, old_name)
  alias_method(new_name, old_name)
  alias_writer(new_name)
  add_attribute_name(new_name)
end
dsl_attribute_names() click to toggle source
# File lib/avro/builder/dsl_attributes.rb, line 52
def dsl_attribute_names
  @dsl_attribute_names ||=
    if superclass.respond_to?(:dsl_attribute_names)
      superclass.dsl_attribute_names.dup
    else
      Set.new
    end
end
dsl_attributes(*names) click to toggle source
# File lib/avro/builder/dsl_attributes.rb, line 37
def dsl_attributes(*names)
  raise 'a block can only be specified with dsl_attribute' if block_given?

  names.each do |name|
    add_attribute_name(name)
    define_accessor(name)
  end
end

Private Instance Methods

alias_writer(name) click to toggle source

The writer (name=) method is used to set attributes via options.

# File lib/avro/builder/dsl_attributes.rb, line 77
def alias_writer(name)
  writer = "#{name}="
  alias_method(writer, name)
  private(writer)
end
define_accessor(name) click to toggle source
# File lib/avro/builder/dsl_attributes.rb, line 68
def define_accessor(name)
  ivar = :"@#{name}"
  define_method(name) do |value = nil|
    value.nil? ? instance_variable_get(ivar) : instance_variable_set(ivar, value)
  end
  alias_writer(name)
end