mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
move OrderedSet to separate file
This commit is contained in:
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"
|
require "set"
|
||||||
|
|
||||||
module ActiveModel
|
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
|
# Active Model Serializer
|
||||||
#
|
#
|
||||||
# Provides a basic serializer implementation that allows you to easily
|
# 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/core_ext/string/inflections"
|
||||||
require "active_support/notifications"
|
require "active_support/notifications"
|
||||||
require "active_model"
|
require "active_model"
|
||||||
|
require "active_model/ordered_set"
|
||||||
require "active_model/array_serializer"
|
require "active_model/array_serializer"
|
||||||
require "active_model/serializer"
|
require "active_model/serializer"
|
||||||
require "set"
|
require "set"
|
||||||
|
|||||||
Reference in New Issue
Block a user