Module: MediaTypes
- Defined in:
- lib/media_types.rb,
lib/media_types/dsl.rb,
lib/media_types/hash.rb,
lib/media_types/views.rb,
lib/media_types/errors.rb,
lib/media_types/object.rb,
lib/media_types/scheme.rb,
lib/media_types/version.rb,
lib/media_types/formatter.rb,
lib/media_types/dsl/errors.rb,
lib/media_types/validations.rb,
lib/media_types/scheme/links.rb,
lib/media_types/scheme/rules.rb,
lib/media_types/constructable.rb,
lib/media_types/scheme/any_of.rb,
lib/media_types/scheme/errors.rb,
lib/media_types/scheme/allow_nil.rb,
lib/media_types/scheme/attribute.rb,
lib/media_types/scheme/not_strict.rb,
lib/media_types/testing/assertions.rb,
lib/media_types/scheme/output_type_guard.rb,
lib/media_types/scheme/missing_validation.rb,
lib/media_types/scheme/output_empty_guard.rb,
lib/media_types/scheme/validation_options.rb,
lib/media_types/scheme/enumeration_context.rb,
lib/media_types/scheme/enumeration_of_type.rb,
lib/media_types/scheme/rules_exhausted_guard.rb,
lib/media_types/scheme/output_iterator_with_predicate.rb
Defined Under Namespace
Modules: Dsl, Errors, Testing
Classes: AssertionError, Constructable, FixtureData, Formatter, Hash, Object, Scheme, UnexpectedValidationResultError, Validations
Constant Summary
collapse
- SYMBOL_KEYS_DEFAULT =
true
- COLLECTION_VIEW =
Shortcut used by #collection to #view(‘collection’)
'collection'
- INDEX_VIEW =
Shortcut used by #index to #view(‘index’)
'index'
- CREATE_VIEW =
Shortcut used by #create to #view(‘create’)
'create'
- VERSION =
'2.3.2'
Class Method Summary
collapse
Class Method Details
.expect_string_keys(mod) ⇒ Object
20
21
22
|
# File 'lib/media_types.rb', line 20
def self.expect_string_keys(mod)
set_key_expectation(mod, false)
end
|
.expect_symbol_keys(mod) ⇒ Object
24
25
26
|
# File 'lib/media_types.rb', line 24
def self.expect_symbol_keys(mod)
set_key_expectation(mod, true)
end
|
.find_key_expectation(mod) ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/media_types.rb', line 50
def self.find_key_expectation(mod)
modules = mod.name.split('::')
expect_symbol = nil
while modules.any? && expect_symbol.nil?
current_module = modules.join('::')
expect_symbol = @key_expectations[current_module]
@key_expectations_used[current_module] = true
modules.pop
end
expect_symbol
end
|
.get_key_expectation(mod) ⇒ Object
41
42
43
44
45
46
47
48
|
# File 'lib/media_types.rb', line 41
def self.get_key_expectation(mod)
@key_expectations ||= {}
@key_expectations_used ||= {}
expect_symbol = find_key_expectation(mod)
expect_symbol.nil? ? SYMBOL_KEYS_DEFAULT : expect_symbol
end
|
.get_organisation(mod) ⇒ Object
64
65
66
67
68
69
70
71
72
|
# File 'lib/media_types.rb', line 64
def self.get_organisation(mod)
name = mod.name
prefixes = @organisation_prefixes.keys.select { |p| name.start_with? p }
return nil unless prefixes.any?
best = prefixes.max_by { |p| p.length }
@organisation_prefixes[best]
end
|
.set_key_expectation(mod, expect_symbol_keys) ⇒ Object
Keep track of modules setting their key expectations
29
30
31
32
33
34
35
36
37
|
# File 'lib/media_types.rb', line 29
def self.set_key_expectation(mod, expect_symbol_keys)
@key_expectations ||= {}
@key_expectations_used ||= {}
raise KeyExpectationSetError.new(mod: mod) unless @key_expectations[mod.name].nil?
raise KeyExpectationUsedError.new(mod: mod) if @key_expectations_used[mod.name]
@key_expectations[mod.name] = expect_symbol_keys
end
|
.set_organisation(mod, organisation) ⇒ Object
15
16
17
18
|
# File 'lib/media_types.rb', line 15
def self.set_organisation(mod, organisation)
@organisation_prefixes ||= {}
@organisation_prefixes[mod.name] = organisation
end
|