Module: RestPack::Serializer
- Extended by:
- ActiveSupport::Concern
- Includes:
- Attributes, Filterable, Paging, Resource, SideLoading, Single, Sortable
- Defined in:
- lib/restpack_serializer.rb,
lib/restpack_serializer/result.rb,
lib/restpack_serializer/options.rb,
lib/restpack_serializer/version.rb,
lib/restpack_serializer/serializable.rb,
lib/restpack_serializer/configuration.rb,
lib/restpack_serializer/serializable/side_load_data_builder.rb
Defined Under Namespace
Modules: Attributes, ClassMethods, Filterable, Paging, Resource, SideLoading, Single, Sortable
Classes: Configuration, Factory, InvalidInclude, Options, Result, SideLoadDataBuilder
Constant Summary
collapse
- VERSION =
'0.6.10'
- @@config =
Configuration.new
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Attributes
#default_href
Class Method Details
.setup {|@@config| ... } ⇒ Object
16
17
18
|
# File 'lib/restpack_serializer.rb', line 16
def self.setup
yield @@config
end
|
Instance Method Details
#as_json(model, context = {}) ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/restpack_serializer/serializable.rb', line 34
def as_json(model, context = {})
return if model.nil?
if model.kind_of?(Array)
return model.map { |item| self.class.new.as_json(item, context) }
end
apply_whitelist_and_blacklist(context)
@model, @context = model, context
data = {}
if self.class.serializable_attributes.present?
self.class.serializable_attributes.each do |key, attribute|
method_name = attribute[:include_method_name]
name = attribute[:name]
if self.class.memoized_has_user_defined_method?(method_name)
data[key] = self.send(name) if self.send(method_name)
else
if @context[method_name].nil? || @context[method_name]
data[key] = self.send(name)
end
end
end
end
add_custom_attributes(data)
add_links(model, data) unless self.class.associations.empty?
data
end
|
#custom_attributes ⇒ Object
65
66
67
|
# File 'lib/restpack_serializer/serializable.rb', line 65
def custom_attributes
nil
end
|