mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 22:06:50 +00:00
move OrderedSet to separate file
This commit is contained in:
parent
b8f01ba2f3
commit
9584b9e147
25
lib/active_model/ordered_set.rb
Normal file
25
lib/active_model/ordered_set.rb
Normal file
@ -0,0 +1,25 @@
|
||||
module ActiveModel
|
||||
class OrderedSet
|
||||
def initialize(array)
|
||||
@array = array
|
||||
@hash = {}
|
||||
|
||||
array.each do |item|
|
||||
@hash[item] = true
|
||||
end
|
||||
end
|
||||
|
||||
def merge!(other)
|
||||
other.each do |item|
|
||||
next if @hash.key?(item)
|
||||
|
||||
@hash[item] = true
|
||||
@array.push item
|
||||
end
|
||||
end
|
||||
|
||||
def to_a
|
||||
@array
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -3,30 +3,6 @@ require "active_support/core_ext/module/anonymous"
|
||||
require "set"
|
||||
|
||||
module ActiveModel
|
||||
class OrderedSet
|
||||
def initialize(array)
|
||||
@array = array
|
||||
@hash = {}
|
||||
|
||||
array.each do |item|
|
||||
@hash[item] = true
|
||||
end
|
||||
end
|
||||
|
||||
def merge!(other)
|
||||
other.each do |item|
|
||||
next if @hash.key?(item)
|
||||
|
||||
@hash[item] = true
|
||||
@array.push item
|
||||
end
|
||||
end
|
||||
|
||||
def to_a
|
||||
@array
|
||||
end
|
||||
end
|
||||
|
||||
# Active Model Serializer
|
||||
#
|
||||
# Provides a basic serializer implementation that allows you to easily
|
||||
|
||||
@ -2,6 +2,7 @@ require "active_support"
|
||||
require "active_support/core_ext/string/inflections"
|
||||
require "active_support/notifications"
|
||||
require "active_model"
|
||||
require "active_model/ordered_set"
|
||||
require "active_model/array_serializer"
|
||||
require "active_model/serializer"
|
||||
require "set"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user