fast_serializer 1.1.2 → 1.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +52 -0
- data/{MIT_LICENSE → MIT_LICENSE.txt} +1 -1
- data/README.md +32 -3
- data/VERSION +1 -1
- data/fast_serializer.gemspec +27 -19
- data/lib/fast_serializer/array_serializer.rb +11 -5
- data/lib/fast_serializer/cache/active_support_cache.rb +6 -6
- data/lib/fast_serializer/cache.rb +12 -0
- data/lib/fast_serializer/serialization_context.rb +15 -2
- data/lib/fast_serializer/serialized_field.rb +24 -11
- data/lib/fast_serializer/serializer.rb +37 -18
- data/lib/fast_serializer.rb +12 -12
- metadata +14 -79
- data/.gitignore +0 -6
- data/.travis.yml +0 -7
- data/Gemfile +0 -2
- data/Gemfile.lock +0 -50
- data/HISTORY.md +0 -30
- data/Rakefile +0 -6
- data/spec/array_serializer_spec.rb +0 -67
- data/spec/cache/active_support_cache_spec.rb +0 -24
- data/spec/fast_serializer_spec.rb +0 -40
- data/spec/serialization_context_spec.rb +0 -32
- data/spec/serialized_field_spec.rb +0 -82
- data/spec/serializer_spec.rb +0 -177
- data/spec/spec_helper.rb +0 -18
- data/spec/support/test_models.rb +0 -74
data/spec/spec_helper.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'rspec'
|
2
|
-
require 'active_support/cache'
|
3
|
-
require 'active_support/cache/memory_store'
|
4
|
-
require_relative "../lib/fast_serializer"
|
5
|
-
require_relative "support/test_models"
|
6
|
-
|
7
|
-
RSpec.configure do |config|
|
8
|
-
config.run_all_when_everything_filtered = true
|
9
|
-
config.filter_run :focus
|
10
|
-
|
11
|
-
# Run specs in random order to surface order dependencies. If you find an
|
12
|
-
# order dependency and want to debug it, you can fix the order by providing
|
13
|
-
# the seed, which is printed after each run.
|
14
|
-
# --seed 1234
|
15
|
-
config.order = 'random'
|
16
|
-
|
17
|
-
config.expect_with(:rspec) { |c| c.syntax = [:should, :expect] }
|
18
|
-
end
|
data/spec/support/test_models.rb
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
class SimpleModel
|
2
|
-
attr_reader :id, :name, :description, :associations, :number
|
3
|
-
attr_accessor :parent
|
4
|
-
|
5
|
-
def initialize(attributes = {})
|
6
|
-
@id = attributes[:id]
|
7
|
-
@name = attributes[:name]
|
8
|
-
@description = attributes[:description]
|
9
|
-
@validated = attributes[:validated]
|
10
|
-
@associations = attributes[:associations]
|
11
|
-
@parent = attributes[:parent]
|
12
|
-
@number = attributes[:number]
|
13
|
-
end
|
14
|
-
|
15
|
-
def validated?
|
16
|
-
!!@validated
|
17
|
-
end
|
18
|
-
|
19
|
-
def as_json(*args)
|
20
|
-
{:id => @id, :name => @name, :description => @description, :number => @number}
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
class TestCache < FastSerializer::Cache
|
25
|
-
def initialize
|
26
|
-
@cache = {}
|
27
|
-
end
|
28
|
-
|
29
|
-
def fetch(serializer, ttl)
|
30
|
-
val = @cache[serializer.cache_key]
|
31
|
-
unless val
|
32
|
-
val = yield
|
33
|
-
@cache[serializer.cache_key] = val
|
34
|
-
end
|
35
|
-
val
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
class SimpleSerializer
|
40
|
-
include FastSerializer::Serializer
|
41
|
-
|
42
|
-
serialize :id, :name, :validated?
|
43
|
-
serialize :description, optional: true
|
44
|
-
serialize :number, as: :amount, optional: true
|
45
|
-
end
|
46
|
-
|
47
|
-
class CachedSerializer < SimpleSerializer
|
48
|
-
cacheable ttl: 2, cache: TestCache.new
|
49
|
-
end
|
50
|
-
|
51
|
-
class ComplexSerializer < SimpleSerializer
|
52
|
-
serialize :serial_number, delegate: false
|
53
|
-
serialize :associations, delegate: true, serializer: CachedSerializer, enumerable: true
|
54
|
-
serialize :parent, delegate: true, serializer: SimpleSerializer, serializer_options: {include: :description}
|
55
|
-
|
56
|
-
def serial_number
|
57
|
-
option(:serial_number)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
class CircularSerializer < SimpleSerializer
|
62
|
-
remove :name, :validated
|
63
|
-
serialize :parent, serializer: self
|
64
|
-
end
|
65
|
-
|
66
|
-
class ConditionalSerializer < SimpleSerializer
|
67
|
-
remove :validated
|
68
|
-
serialize :description, if: -> { scope == :description }
|
69
|
-
serialize :name, if: :show_name?
|
70
|
-
|
71
|
-
def show_name?
|
72
|
-
scope == :name
|
73
|
-
end
|
74
|
-
end
|