Sha256: f30940c06d537b32cb38b21626fc8b9983b14064f10f49218bef0df1135ef1d2

Contents?: true

Size: 876 Bytes

Versions: 8

Compression:

Stored size: 876 Bytes

Contents

require 'active_support/core_ext/hash/indifferent_access'
module ActiveHash

  module ARApi

    module Init

      attr_reader :associations

      def initialize(attributes = {})
        filter_associations(HashWithIndifferentAccess.new(attributes))
        @attributes.dup.merge(@associations.dup).each do |key, value|
          send "#{key}=", value
        end
      end

      private

      def filter_associations(attributes)
        @attributes = attributes.select do |k, v|
          self.class.send(:attribute_names).include? k.to_sym
        end
        @attributes = self.class.send(:attribute_template).merge(@attributes)
        @associations = attributes.select do |k, v|
          self.class.send(:association_names).include? k.to_sym
        end
        @associations = self.class.send(:association_template).merge(associations)
      end

    end
  end

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
active_mocker-1.1.22 lib/active_hash/init.rb
active_mocker-1.1.21 lib/active_hash/init.rb
active_mocker-1.1.20 lib/active_hash/init.rb
active_mocker-1.1.11 lib/active_hash/init.rb
active_mocker-1.1.10 lib/active_hash/init.rb
active_mocker-1.1.9 lib/active_hash/init.rb
active_mocker-1.1.8 lib/active_hash/init.rb
active_mocker-1.1.7 lib/active_hash/init.rb