module YASL

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.

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.

Constants

JSON_BASIC_DATA_TYPES
RUBY_BASIC_DATA_TYPES
RUBY_ONLY_BASIC_DATA_TYPES
UNSERIALIZABLE_DATA_TYPES

Public Class Methods

dump(object, include_classes: false) click to toggle source
# 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) click to toggle source
# 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: []) click to toggle source
# 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) click to toggle source
# File lib/yasl.rb, line 46
def ruby_basic_data_type?(object)
  type_in?(object, RUBY_BASIC_DATA_TYPES)
end

Private Class Methods

type_in?(object, types) click to toggle source
# File lib/yasl.rb, line 52
def type_in?(object, types)
  types.reduce(false) do |result, class_name|
    result || object.class.ancestors.map(&:name).include?(class_name)
  end
end