Class: Yaks::Format
- Inherits:
-
Object
show all
- Extended by:
- Forwardable, Util::Deprecated
- Includes:
- Yaks::FP::Callable, Util
- Defined in:
- lib/yaks/format.rb,
lib/yaks/format/hal.rb,
lib/yaks/format/halo.rb,
lib/yaks/format/json_api.rb,
lib/yaks/format/collection_json.rb
Defined Under Namespace
Classes: CollectionJson, Hal, Halo, JsonAPI, Reader
Class Attribute Summary collapse
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
deprecated_alias
Methods included from Util
#Resolve, #camelize, #extract_options, #reject_keys, #slice_hash, #symbolize_keys, #underscore
#to_proc
Constructor Details
#initialize(options = {}) ⇒ Hash
19
20
21
|
# File 'lib/yaks/format.rb', line 19
def initialize(options = {})
@options = options
end
|
Class Attribute Details
Returns the value of attribute format_name.
38
39
40
|
# File 'lib/yaks/format.rb', line 38
def format_name
@format_name
end
|
Returns the value of attribute media_type.
38
39
40
|
# File 'lib/yaks/format.rb', line 38
def media_type
@media_type
end
|
.serializer ⇒ Object
Returns the value of attribute serializer.
38
39
40
|
# File 'lib/yaks/format.rb', line 38
def serializer
@serializer
end
|
Instance Attribute Details
#env ⇒ Object
Returns the value of attribute env.
11
12
13
|
# File 'lib/yaks/format.rb', line 11
def env
@env
end
|
Class Method Details
.all ⇒ Object
42
43
44
|
# File 'lib/yaks/format.rb', line 42
def all
@formats ||= []
end
|
73
74
75
76
77
78
79
80
|
# File 'lib/yaks/format.rb', line 73
def ()
media_type = Rack::Accept::Charset.new().best_of(media_types.values)
if media_type
by_media_type(media_type)
else
yield if block_given?
end
end
|
68
69
70
|
# File 'lib/yaks/format.rb', line 68
def by_media_type(media_type)
find(:media_type, media_type)
end
|
.by_name(format_name) ⇒ Constant
61
62
63
|
# File 'lib/yaks/format.rb', line 61
def by_name(format_name)
find(:format_name, format_name)
end
|
82
83
84
85
86
|
# File 'lib/yaks/format.rb', line 82
def media_types
Format.all.each_with_object({}) do |format, memo|
memo[format.format_name] = format.media_type
end
end
|
.names ⇒ Object
89
90
91
|
# File 'lib/yaks/format.rb', line 89
def names
media_types.keys
end
|
.register(format_name, serializer, media_type) ⇒ Array
50
51
52
53
54
55
56
|
# File 'lib/yaks/format.rb', line 50
def register(format_name, serializer, media_type)
@format_name = format_name
@serializer = serializer
@media_type = media_type
Format.all << self
end
|
Instance Method Details
#call(resource, env = {}) ⇒ Hash
Also known as:
serialize
25
26
27
28
|
# File 'lib/yaks/format.rb', line 25
def call(resource, env = {})
@env = env
serialize_resource(resource)
end
|
#serialize_resource(_resource) ⇒ Object
32
33
|
# File 'lib/yaks/format.rb', line 32
def serialize_resource(_resource)
end
|