instance method has_delegated_json

Ruby on Rails edge

Since edge

Signature

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

attr req
schema keyrest
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

Type at least 2 characters to search.

Use the arrow keys to navigate results, Enter to open one, Escape to close.

Keyboard shortcuts

/
Focus search
⌘K / Ctrl-K
Command palette
?
This help
Esc
Close