Module: Avro::Builder::DslAttributes::ClassMethods

Defined in:
lib/avro/builder/dsl_attributes.rb

Instance Method Summary collapse

Instance Method Details

#add_attribute_name(name) ⇒ Object



84
85
86
87
88
89
90
91
# File 'lib/avro/builder/dsl_attributes.rb', line 84

def add_attribute_name(name)
  unless ATTRIBUTE_NAMES.include?(name)
    raise "DSL attribute #{name.inspect} must be added to Avro::Builder::DslAttributes::RESERVED_NAMES"
  end

  dsl_attribute_names << name
  add_option_name(name)
end

#dsl_attribute(name, &block) ⇒ Object

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



50
51
52
53
54
55
56
57
58
# File 'lib/avro/builder/dsl_attributes.rb', line 50

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) ⇒ Object



69
70
71
72
73
# File 'lib/avro/builder/dsl_attributes.rb', line 69

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 ⇒ Object



75
76
77
78
79
80
81
82
# File 'lib/avro/builder/dsl_attributes.rb', line 75

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) ⇒ Object



60
61
62
63
64
65
66
67
# File 'lib/avro/builder/dsl_attributes.rb', line 60

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