Sha256: 57232cb47a80080d68178bd68915aa2f442628eea6008d650bf4dabb725832ee

Contents?: true

Size: 1.33 KB

Versions: 72

Compression:

Stored size: 1.33 KB

Contents

module Clamp
  module Attribute

    module Declaration

      protected

      def define_accessors_for(attribute, &block)
        define_reader_for(attribute)
        define_default_for(attribute)
        if attribute.multivalued?
          define_appender_for(attribute, &block)
          define_multi_writer_for(attribute)
        else
          define_simple_writer_for(attribute, &block)
        end
      end

      def define_reader_for(attribute)
        define_method(attribute.read_method) do
          attribute.of(self)._read
        end
      end

      def define_default_for(attribute)
        define_method(attribute.default_method) do
          attribute.default_value
        end
      end

      def define_simple_writer_for(attribute, &block)
        define_method(attribute.write_method) do |value|
          value = instance_exec(value, &block) if block
          attribute.of(self).set(value)
        end
      end

      def define_appender_for(attribute, &block)
        define_method(attribute.append_method) do |value|
          value = instance_exec(value, &block) if block
          attribute.of(self)._append(value)
        end
      end

      def define_multi_writer_for(attribute)
        define_method(attribute.write_method) do |values|
          attribute.of(self)._replace(values)
        end
      end

    end

  end
end

Version data entries

72 entries across 68 versions & 18 rubygems

Version Path
logstash-output-scalyr-0.2.1.beta vendor/bundle/jruby/2.5.0/gems/clamp-0.6.5/lib/clamp/attribute/declaration.rb
logstash-output-scalyr-0.2.0 vendor/bundle/jruby/2.5.0/gems/clamp-0.6.5/lib/clamp/attribute/declaration.rb
logstash-output-scalyr-0.2.0.beta vendor/bundle/jruby/2.5.0/gems/clamp-0.6.5/lib/clamp/attribute/declaration.rb
logstash-output-scalyr-0.1.26.beta vendor/bundle/jruby/2.5.0/gems/clamp-0.6.5/lib/clamp/attribute/declaration.rb
logstash-output-scalyr-0.1.25.beta vendor/bundle/jruby/2.5.0/gems/clamp-0.6.5/lib/clamp/attribute/declaration.rb
logstash-output-scalyr-0.1.24.beta vendor/bundle/jruby/2.5.0/gems/clamp-0.6.5/lib/clamp/attribute/declaration.rb
logstash-output-scalyr-0.1.23.beta vendor/bundle/jruby/2.5.0/gems/clamp-0.6.5/lib/clamp/attribute/declaration.rb
logstash-output-scalyr-0.1.22.beta vendor/bundle/jruby/2.5.0/gems/clamp-0.6.5/lib/clamp/attribute/declaration.rb
logstash-output-scalyr-0.1.21.beta vendor/bundle/jruby/2.5.0/gems/clamp-0.6.5/lib/clamp/attribute/declaration.rb
logstash-output-scalyr-0.1.20.beta vendor/bundle/jruby/2.5.0/gems/clamp-0.6.5/lib/clamp/attribute/declaration.rb
logstash-output-scalyr-0.1.19.beta vendor/bundle/jruby/2.5.0/gems/clamp-0.6.5/lib/clamp/attribute/declaration.rb
logstash-output-scalyr-0.1.18.beta vendor/bundle/jruby/2.5.0/gems/clamp-0.6.5/lib/clamp/attribute/declaration.rb
logstash-output-scalyr-0.1.17.beta vendor/bundle/jruby/2.5.0/gems/clamp-0.6.5/lib/clamp/attribute/declaration.rb
logstash-output-scalyr-0.1.16.beta vendor/bundle/jruby/2.5.0/gems/clamp-0.6.5/lib/clamp/attribute/declaration.rb
logstash-output-scalyr-0.1.15.beta vendor/bundle/jruby/2.5.0/gems/clamp-0.6.5/lib/clamp/attribute/declaration.rb
logstash-output-scalyr-0.1.14.beta vendor/bundle/jruby/2.5.0/gems/clamp-0.6.5/lib/clamp/attribute/declaration.rb
logstash-output-scalyr-0.1.13 vendor/bundle/jruby/2.5.0/gems/clamp-0.6.5/lib/clamp/attribute/declaration.rb
logstash-output-scalyr-0.1.12 vendor/bundle/jruby/2.5.0/gems/clamp-0.6.5/lib/clamp/attribute/declaration.rb
logstash-output-scalyr-0.1.11.beta vendor/bundle/jruby/2.5.0/gems/clamp-0.6.5/lib/clamp/attribute/declaration.rb
logstash-output-scalyr-0.1.10.beta vendor/bundle/jruby/2.5.0/gems/clamp-0.6.5/lib/clamp/attribute/declaration.rb