Sha256: 942e006c39a51ddc2c7e52a9ced10ff5ae799a60116e0fb59af23ec70664f3ba

Contents?: true

Size: 1.34 KB

Versions: 13

Compression:

Stored size: 1.34 KB

Contents

module Avro
  module Builder

    # This module provides methods for defining options that can be
    # set via the DSL on various objects.
    #
    # These attributes can only be set as options via the private
    # #attribute= methods, and not as methods in DSL block.
    #
    # When a DSL option is defined, the class also keeps track of the
    # option names.
    module DslOptions
      def self.included(base)
        base.extend ClassMethods
      end

      def dsl_option?(name)
        self.class.dsl_option_names.include?(name.to_sym)
      end

      module ClassMethods

        # Defines a private writer with #{dsl_name}= to set an attribute stored in the
        # instance variable @#{name}.
        def dsl_option(name, dsl_name:)
          add_option_name(name)
          add_attribute_name(dsl_name)
          aliased_writer = "#{dsl_name}="
          define_method(aliased_writer) do |value|
            instance_variable_set("@#{name}", value)
          end
          private(aliased_writer)
        end

        def dsl_option_names
          @dsl_option_names ||=
            if superclass.respond_to?(:dsl_option_names)
              superclass.dsl_option_names.dup
            else
              Set.new
            end
        end

        def add_option_name(name)
          dsl_option_names << name
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
avro-builder-0.16.1 lib/avro/builder/dsl_options.rb
avro-builder-0.16.0 lib/avro/builder/dsl_options.rb
avro-builder-0.15.0 lib/avro/builder/dsl_options.rb
avro-builder-0.15.0.rc0 lib/avro/builder/dsl_options.rb
avro-builder-0.14.1 lib/avro/builder/dsl_options.rb
avro-builder-0.14.0 lib/avro/builder/dsl_options.rb
avro-builder-0.13.0 lib/avro/builder/dsl_options.rb
avro-builder-0.12.0 lib/avro/builder/dsl_options.rb
avro-builder-0.11.0 lib/avro/builder/dsl_options.rb
avro-builder-0.10.0 lib/avro/builder/dsl_options.rb
avro-builder-0.9.0 lib/avro/builder/dsl_options.rb
avro-builder-0.8.0 lib/avro/builder/dsl_options.rb
avro-builder-0.7.0 lib/avro/builder/dsl_options.rb