literal
literal copied to clipboard
feat: Make data structs implicitly Hash coercible
This allows using Literal::Data (and its friends) like so:
class Person < Literal::Data
prop :first_name, String
prop :last_name, String
end
john = Person.new(first_name: "John", last_name: "Doe")
jane = Person.new(**john, first_name: "Jane")
This is especially useful when we use Data/Struct as configuration options data:
class Shrine
module Plugins
module Example
class Options < Literal::Data
# ...
end
DEFAULT_OPTIONS = { ... }
def self.configure(uploader, **options)
uploader.opts[:example] = Options.new(
**DEFAULT_OPTIONS,
**uploader.opts[:example],
**options
)
end
end
register_plugin(:example, Example)
end
end