Class: CollectionJson::Serializer

Inherits:
Object
  • Object
show all
Defined in:
lib/collection_json_serializer/items.rb,
lib/collection_json_serializer/builder.rb,
lib/collection_json_serializer/support.rb,
lib/collection_json_serializer/version.rb,
lib/collection_json_serializer/validator.rb,
lib/collection_json_serializer/serializer.rb,
lib/collection_json_serializer/objects/item.rb,
lib/collection_json_serializer/objects/query.rb,
lib/collection_json_serializer/validator/url.rb,
lib/collection_json_serializer/validator/value.rb,
lib/collection_json_serializer/objects/template.rb

Defined Under Namespace

Modules: Support Classes: Builder, Items, Objects, Validator

Constant Summary collapse

VERSION =
"0.3.2"

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource) ⇒ Serializer

Returns a new instance of Serializer.



47
48
49
50
51
52
53
# File 'lib/collection_json_serializer/serializer.rb', line 47

def initialize(resource)
  @resources = if resource.respond_to? :to_ary
                 resource
               else
                 [resource]
               end
end

Class Attribute Details

._itemsObject

Returns the value of attribute _items.



9
10
11
# File 'lib/collection_json_serializer/serializer.rb', line 9

def _items
  @_items
end

.extensions(*attrs) ⇒ Object

Returns the value of attribute extensions.



4
5
6
# File 'lib/collection_json_serializer/serializer.rb', line 4

def extensions
  @extensions
end

.href(*attrs) ⇒ Object

Returns the value of attribute href.



5
6
7
# File 'lib/collection_json_serializer/serializer.rb', line 5

def href
  @href
end

Returns the value of attribute links.



7
8
9
# File 'lib/collection_json_serializer/serializer.rb', line 7

def links
  @links
end

.queries(*attrs) ⇒ Object

Returns the value of attribute queries.



8
9
10
# File 'lib/collection_json_serializer/serializer.rb', line 8

def queries
  @queries
end

.template(*attrs) ⇒ Object

Returns the value of attribute template.



6
7
8
# File 'lib/collection_json_serializer/serializer.rb', line 6

def template
  @template
end

Instance Attribute Details

#resourcesObject

Returns the value of attribute resources.



45
46
47
# File 'lib/collection_json_serializer/serializer.rb', line 45

def resources
  @resources
end

Class Method Details

.inherited(base) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/collection_json_serializer/serializer.rb', line 12

def self.inherited(base)
  base.extensions = []
  base.href = []
  base.template = []
  base.links = []
  base.queries = []
end

.items(&block) ⇒ Object



40
41
42
43
# File 'lib/collection_json_serializer/serializer.rb', line 40

def self.items(&block)
  @_items = Items.new
  @_items.instance_eval(&block)
end

Instance Method Details

#errorsObject



107
108
109
# File 'lib/collection_json_serializer/serializer.rb', line 107

def errors
  Validator.new(self).errors
end

#extensionsObject



55
56
57
# File 'lib/collection_json_serializer/serializer.rb', line 55

def extensions
  self.class.extensions
end

#hrefObject



59
60
61
# File 'lib/collection_json_serializer/serializer.rb', line 59

def href
  self.class.href.first
end

#invalid?Boolean

Returns:

  • (Boolean)


99
100
101
# File 'lib/collection_json_serializer/serializer.rb', line 99

def invalid?
  Validator.new(self).invalid?
end

#itemsObject



87
88
89
# File 'lib/collection_json_serializer/serializer.rb', line 87

def items
  self.class._items
end

#items?Boolean

Returns:

  • (Boolean)


91
92
93
# File 'lib/collection_json_serializer/serializer.rb', line 91

def items?
  self.class._items.present?
end


71
72
73
# File 'lib/collection_json_serializer/serializer.rb', line 71

def links
  self.class.links
end

#links?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/collection_json_serializer/serializer.rb', line 75

def links?
  self.class.links.present?
end

#queriesObject



79
80
81
# File 'lib/collection_json_serializer/serializer.rb', line 79

def queries
  self.class.queries
end

#queries?Boolean

Returns:

  • (Boolean)


83
84
85
# File 'lib/collection_json_serializer/serializer.rb', line 83

def queries?
  self.class.queries.present?
end

#templateObject



63
64
65
# File 'lib/collection_json_serializer/serializer.rb', line 63

def template
  self.class.template
end

#template?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/collection_json_serializer/serializer.rb', line 67

def template?
  self.class.template.present?
end

#uses?(extension) ⇒ Boolean

Returns:

  • (Boolean)


95
96
97
# File 'lib/collection_json_serializer/serializer.rb', line 95

def uses?(extension)
  extensions.include?(extension)
end

#valid?Boolean

Returns:

  • (Boolean)


103
104
105
# File 'lib/collection_json_serializer/serializer.rb', line 103

def valid?
  Validator.new(self).valid?
end