fast_serializer 1.1.2 → 1.1.4

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -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