Sha256: dc8d00f38454740172480bb39b0e018d57490a93a06f37590038df36e92ce11a

Contents?: true

Size: 864 Bytes

Versions: 1

Compression:

Stored size: 864 Bytes

Contents

module EnoughFields
  class Attributes < ActiveSupport::HashWithIndifferentAccess
    class <<self
      attr_accessor :klass

      def build(klass, attributes)
        @klass = klass
        self[attributes]
      end

      def [](attributes)
        return super unless Thread.current[:monit_set]

        hash = super
        hash.each do |key, value|
          next if key.is_a? Array
          attribute_value = AttributeValue.new(value, @klass, key, caller.find_all { |c| c.index Rails.root })
          hash[ key ] = attribute_value
          Thread.current[:monit_set] << attribute_value
        end
        hash
      end
    end

    def [](key)
      return super unless Thread.current[:monit_set]

      if super && super.is_a?(AttributeValue)
        super.call_stack = nil
        super.to_value
      else
        super
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
enough_fields-0.0.1 lib/enough_fields/attributes.rb