Sha256: 41355c4475c364bd99434c606c7806bef5e496d1a696aa1fc85b7f4194d1aac4

Contents?: true

Size: 1.19 KB

Versions: 16

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

module Unparser
  class Anima
    # An attribute
    class Attribute
      include Adamantium, Equalizer.new(:name)

      # Initialize attribute
      #
      # @param [Symbol] name
      def initialize(name)
        @name = name
        @instance_variable_name = :"@#{name}"
      end

      # Return attribute name
      #
      # @return [Symbol]
      attr_reader :name

      # Return instance variable name
      #
      # @return [Symbol]
      attr_reader :instance_variable_name

      # Load attribute
      #
      # @param [Object] object
      # @param [Hash] attributes
      #
      # @return [self]
      def load(object, attributes)
        set(object, attributes.fetch(name))
      end

      # Get attribute value from object
      #
      # @param [Object] object
      #
      # @return [Object]
      def get(object)
        object.public_send(name)
      end

      # Set attribute value in object
      #
      # @param [Object] object
      # @param [Object] value
      #
      # @return [self]
      def set(object, value)
        object.instance_variable_set(instance_variable_name, value)

        self
      end
    end # Attribute
  end # Anima
end # Unparser

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
unparser-0.6.15 lib/unparser/anima/attribute.rb
unparser-0.6.14 lib/unparser/anima/attribute.rb
unparser-0.6.13 lib/unparser/anima/attribute.rb
unparser-0.6.12 lib/unparser/anima/attribute.rb
unparser-0.6.10 lib/unparser/anima/attribute.rb
unparser-0.6.9 lib/unparser/anima/attribute.rb
unparser-0.6.8 lib/unparser/anima/attribute.rb
devcycle-ruby-server-sdk-2.0.0 vendor/bundle/ruby/3.0.0/gems/unparser-0.6.7/lib/unparser/anima/attribute.rb
unparser-0.6.7 lib/unparser/anima/attribute.rb
unparser-0.6.6 lib/unparser/anima/attribute.rb
unparser-0.6.5 lib/unparser/anima/attribute.rb
unparser-0.6.4 lib/unparser/anima/attribute.rb
unparser-0.6.3 lib/unparser/anima/attribute.rb
unparser-0.6.2 lib/unparser/anima/attribute.rb
unparser-0.6.1 lib/unparser/anima/attribute.rb
unparser-0.6.0 lib/unparser/anima/attribute.rb