lib/lutaml/model/serialize.rb in lutaml-model-0.3.5 vs lib/lutaml/model/serialize.rb in lutaml-model-0.3.6
- old
+ new
@@ -11,12 +11,10 @@
require_relative "comparable_model"
module Lutaml
module Model
module Serialize
- FORMATS = %i[xml json yaml toml].freeze
-
include ComparableModel
def self.included(base)
base.extend(ClassMethods)
end
@@ -71,11 +69,11 @@
value = attr.default if value.nil?
attr.options[:values].include?(value)
end
- FORMATS.each do |format|
+ Lutaml::Model::Config::AVAILABLE_FORMATS.each do |format|
define_method(format) do |&block|
klass = format == :xml ? XmlMapping : KeyValueMapping
mappings[format] = klass.new
mappings[format].instance_eval(&block)
@@ -430,17 +428,17 @@
def ordered?
@ordered
end
def key_exist?(hash, key)
- hash.key?(key) || hash.key?(key.to_sym) || hash.key?(key.to_s)
+ hash.key?(key.to_sym) || hash.key?(key.to_s)
end
def key_value(hash, key)
- hash[key] || hash[key.to_sym] || hash[key.to_s]
+ hash[key.to_sym] || hash[key.to_s]
end
- FORMATS.each do |format|
+ Lutaml::Model::Config::AVAILABLE_FORMATS.each do |format|
define_method(:"to_#{format}") do |options = {}|
validate
adapter = Lutaml::Model::Config.public_send(:"#{format}_adapter")
representation = if format == :xml
self