instance method
has_delegated_json
Ruby on Rails edge
Since edgeSignature
has_delegated_json(attr, **schema)
Like has_json but each schema key also becomes its own set of accessor methods.
class Account < ApplicationRecord
has_delegated_json :flags, beta: false, staff: :boolean
end
a = Account.new
a.beta? # => false
a.beta = true
a.beta # => true
Parameters
-
attrreq -
schemakeyrest
Source
# File activemodel/lib/active_model/schematized_json.rb, line 58
def has_delegated_json(attr, **schema)
has_json attr, **schema
schema.each_key do |schema_key|
define_method(schema_key) { public_send(attr).public_send(schema_key) }
define_method("#{schema_key}?") { public_send(attr).public_send("#{schema_key}?") }
define_method("#{schema_key}=") { |value| send(attr).public_send("#{schema_key}=", value) }
end
end
Defined in activemodel/lib/active_model/schematized_json.rb line 58
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveModel::SchematizedJson::ClassMethods