Module: YASL

Defined in:
lib/yasl/dumper.rb,
lib/yasl.rb,
lib/yasl/loader.rb

Overview

Copyright © 2020 Andy Maleh

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Defined Under Namespace

Classes: Dumper, Loader

Constant Summary collapse

JSON_BASIC_DATA_TYPES =
['NilClass', 'String', 'Integer', 'Float', 'TrueClass', 'FalseClass', 'Boolean']
RUBY_ONLY_BASIC_DATA_TYPES =
['Time', 'Date', 'BigDecimal', 'Complex', 'Rational', 'Regexp', 'Symbol', 'Set', 'Range', 'Array', 'Hash']
RUBY_BASIC_DATA_TYPES =
RUBY_ONLY_BASIC_DATA_TYPES + JSON_BASIC_DATA_TYPES
UNSERIALIZABLE_DATA_TYPES =
['Proc', 'Binding', 'IO', 'File::Stat', 'Dir', 'BasicSocket', 'MatchData', 'Method', 'UnboundMethod', 'Thread', 'ThreadGroup', 'Continuation']

Class Method Summary collapse

Class Method Details

.dump(object, include_classes: false) ⇒ Object



34
35
36
# File 'lib/yasl.rb', line 34

def dump(object, include_classes: false)
  JSON.dump(Dumper.new(object).dump(include_classes: include_classes))
end

.json_basic_data_type?(object) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/yasl.rb', line 42

def json_basic_data_type?(object)
  type_in?(object, JSON_BASIC_DATA_TYPES)
end

.load(data, include_classes: false, whitelist_classes: []) ⇒ Object



38
39
40
# File 'lib/yasl.rb', line 38

def load(data, include_classes: false, whitelist_classes: [])
  Loader.new(JSON.load(data), whitelist_classes: whitelist_classes).load(include_classes: include_classes)
end

.ruby_basic_data_type?(object) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/yasl.rb', line 46

def ruby_basic_data_type?(object)
  type_in?(object, RUBY_BASIC_DATA_TYPES)
end