Module: JSONAPIonify

Extended by:
Autoload
Defined in:
lib/jsonapionify.rb,
lib/jsonapionify/version.rb,
lib/jsonapionify/autoload.rb,
lib/jsonapionify/callbacks.rb,
lib/jsonapionify/structure.rb,
lib/jsonapionify/continuation.rb,
lib/jsonapionify/documentation.rb,
lib/jsonapionify/api/test_helper.rb,
lib/jsonapionify/character_range.rb,
lib/jsonapionify/indented_string.rb,
lib/jsonapionify/api/errors_object.rb,
lib/jsonapionify/deep_sort_collection.rb,
lib/jsonapionify/inherited_attributes.rb

Defined Under Namespace

Modules: Api, Autoload, Callbacks, DeepSortCollection, DestructuredProc, IndentedString, InheritedAttributes, Structure, Types Classes: CharacterRange, Continuation, CustomRescue, Documentation

Constant Summary collapse

TRUTHY_STRINGS =
%w(t true y yes 1).flat_map do |str|
  [str.downcase, str.upcase, str.capitalize]
end.uniq
FALSEY_STRINGS =
%w(f false n no 0).flat_map do |str|
  [str.downcase, str.upcase, str.capitalize]
end.uniq
VERSION =
"0.12.10"

Class Method Summary collapse

Methods included from Autoload

autoload_all, eager_load!, unloaded

Class Method Details

.cache(store, *args) ⇒ Object



35
36
37
# File 'lib/jsonapionify.rb', line 35

def self.cache(store, *args)
  self.cache_store = ActiveSupport::Cache.lookup_store(store, *args)
end

.cache_storeObject



92
93
94
# File 'lib/jsonapionify.rb', line 92

def self.cache_store
  @cache_store ||= ActiveSupport::Cache.lookup_store :null_store
end

.cache_store=(store) ⇒ Object



80
81
82
# File 'lib/jsonapionify.rb', line 80

def self.cache_store=(store)
  @cache_store = store
end

.digestObject



45
46
47
48
49
50
51
52
# File 'lib/jsonapionify.rb', line 45

def self.digest
  @digest ||=
    files.map do |f|
      File.read f
    end.reduce(
      Digest::SHA2.new, :update
    ).to_s
end

.disable_validation(bool) ⇒ Object



84
85
86
# File 'lib/jsonapionify.rb', line 84

def self.disable_validation(bool)
  @validation_disabled = bool
end

.filesObject



39
40
41
42
43
# File 'lib/jsonapionify.rb', line 39

def self.files
  files = Dir.glob(File.join __dir__, './**/*.rb').map { |f| File.expand_path f }
  files << File.expand_path('./jsonapionify/documentation/template.erb', __dir__)
  files.sort
end

.loggerObject



76
77
78
# File 'lib/jsonapionify.rb', line 76

def self.logger
  @logger ||= defined?(Rails) ? Rails.logger : Logger.new('/dev/null')
end

.logger=(logger) ⇒ Object



72
73
74
# File 'lib/jsonapionify.rb', line 72

def self.logger=(logger)
  @logger = logger
end

.new_object(*args) ⇒ Object



31
32
33
# File 'lib/jsonapionify.rb', line 31

def self.new_object(*args)
  Structure::Objects::TopLevel.new(*args)
end

.parse(hash) ⇒ Object



26
27
28
29
# File 'lib/jsonapionify.rb', line 26

def self.parse(hash)
  hash = Oj.load(hash) if hash.is_a? String
  Structure::Objects::TopLevel.from_hash(hash)
end

.pathObject



22
23
24
# File 'lib/jsonapionify.rb', line 22

def self.path
  __dir__
end

.show_backtraceObject



67
68
69
70
# File 'lib/jsonapionify.rb', line 67

def self.show_backtrace
  return @show_backtrace if instance_variable_defined?(:@show_backtrace)
  self.show_backtrace = ENV['RACK_ENV'] != 'production'
end

.show_backtrace=(value) ⇒ Object



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

def self.show_backtrace=(value)
  @show_backtrace = value
end

.validation_disabled?Boolean

Returns:



88
89
90
# File 'lib/jsonapionify.rb', line 88

def self.validation_disabled?
  !!@validation_disabled
end

.verbose_errorsObject



58
59
60
61
# File 'lib/jsonapionify.rb', line 58

def self.verbose_errors
  return @verbose_errors if instance_variable_defined?(:@verbose_errors)
  self.verbose_errors = ENV['RACK_ENV'] != 'production'
end

.verbose_errors=(value) ⇒ Object



54
55
56
# File 'lib/jsonapionify.rb', line 54

def self.verbose_errors=(value)
  self.show_backtrace = @verbose_errors = value
end