class

Jbuilder

Inherits Reference < Object

Constants

BLANK = Blank.new

Constructors

new(key_formatter : KeyFormatter | Nil = nil, ignore_nil : Bool = @@ignore_nil, deep_format_keys : Bool = @@deep_format_keys, &)
Source
new(key_formatter : KeyFormatter | Nil = nil, ignore_nil : Bool = @@ignore_nil, deep_format_keys : Bool = @@deep_format_keys)
Source

Class methods

_coerce_formats(formats) : Array(KeyFormatter::Func)
Source
deep_format_keys(value : Bool = true) : Nil
Source
encode

Jbuilder.encode { |json| ... } → JSON-строка.

Source
ignore_nil(value : Bool = true) : Nil
Source
key_format(*formats, camelize : Symbol | Nil = nil) : Nil
Source

Instance methods

_array_with_attributes(collection, keys : Array(String)) : Array(Node)

Коллекция с атрибутами: array! people, :name, :age / json.comments comments, :content.

Source
_blank?(value : Node = @attributes) : Bool
Source
_deep_format_keys(node : Node) : Node
Source
_deep_merge(base : Hash(String, Node), updates : Hash(String, Node)) : Hash(String, Node)
Source
_extract_value(object : Hash, key : String) : Node
Source
_extract_value(object : NamedTuple, key : String) : Node
Source
_extract_value(object : JSON::Any, key : String) : Node
Source
_extract_value(object : T, key : String) : Node forall T
Source
_fetch_or_blank(key : String) : Node
Source
_format_keys(node : Node) : Node
Source
_is_collection?(object) : Bool
Source
_key(key : String) : String
Source
_ks(key : String) : String

Ключ: String или Symbol → String (runtime, т.к. через method_missing аргументы приходят как значения).

Source
_ks(key : Symbol) : String
Source
_merge_attributes(node : Node) : Nil
Source
_merge_block(key : String, &) : Node
Source
_merge_values(current_value : Node, updates : Node) : Node
Source
_scope
Source
_set_array(array) : Nil

Без рестрикшена Array(Node): рекурсивный alias в ограничении аргумента не матчит фактический Array(Node) при вызове из тела метода, унаследо- ванного подклассом (json.array! в JbuilderTemplate уводило вызов в method_missing с ключом "_set_array") — см. баги Crystal 1.21 ниже.

Source
_set_value(key : String, value : Node) : Nil
Source
_to_node(value : Nil | Bool | Blank) : Node
Source
_to_node(value : Int32 | Int64 | Float64 | String) : Node
Source
_to_node(value : Float32) : Node
Source
_to_node(value : Int8 | Int16 | UInt8 | UInt16 | UInt32) : Node
Source
_to_node(value : Symbol) : Node
Source
_to_node(value : Array) : Node
Source
_to_node(value : Hash) : Node
Source
_to_node(value : NamedTuple) : Node
Source
_to_node(value : JSON::Any) : Node
Source
_to_node(value : Jbuilder) : Node
Source
_to_node(value) : Node
Source
_to_node_array(value : Nil) : Array(Node)
Source
_to_node_array(value : Array) : Array(Node)
Source
_to_node_array(value) : Array(Node)
Source
_write_json(node : Node, builder : JSON::Builder) : Nil
Source
array!(collection : Nil = nil)

array! — те же ветви, что в Ruby: array! [1,2,3] / array!(nil) / array! coll { |el| ... } / array! coll, :name

Source
array!(collection : Enumerable, *attributes, &)
Source
array!(collection : Enumerable, *attributes)
Source
attributes!

Атрибуты текущего билдера (в Ruby — Object, здесь — Node).

Source
call(object, *attributes)

json.(obj, :name) / json.(coll) { |el| ... } — call-синтаксис (здесь json.call).

Source
call(collection : Enumerable, &)
Source
child!

child! — превращает текущий элемент в массив и добавляет хеш.

Source
deep_format_keys!(value : Bool = true) : Nil
Source
extract!(object, *attributes)

extract! obj, :name, :age — Hash / NamedTuple / JSON::Any / ivar-методы объекта.

Source
ignore_nil!(value : Bool = true) : Nil
Source
key_format!(*formats, camelize : Symbol | Nil = nil) : Nil

key_format! :upcase / key_format! camelize: :lower / key_format! ->(k){ "_"+k } (splat без аннотации: annotated-splat + named-args ломают диспетчеризацию Crystal и приводят к method_missing)

Source
merge!(object : Jbuilder) : Nil

merge! — Hash / NamedTuple / JSON::Any / другой Jbuilder.

Source
merge!(object) : Nil
Source
nil!

nil! / null! — null JSON.

Source
null!
Source
set!(key : String | Symbol, value)

set! — макрос: ветвится по наличию блока/атрибутов, как set! в Ruby. json.name "David" → {"name":"David"} json.author { json.name "David" } → {"author":{...}} json.person other_builder → {"person":{...}} json.people people { |p| ... } → {"people":[...]} json.author david, :name, :age → {"author":{...}} json.comments comments, :content → {"comments":[...]} set! — def-методы (yield-based), те же ветви, что в Ruby: json.name "David" → {"name":"David"} json.author { json.name "David" } → {"author":{...}} json.person other_builder → {"person":{...}} json.people people { |p| ... } → {"people":[...]} json.author david, :name, :age → {"author":{...}} json.comments comments, :content → {"comments":[...]} При блоке атрибуты игнорируются (семантика Ruby: block_given? первым).

Source
set!(key : String | Symbol, value : Enumerable(E), *attributes, &) forall E
Source
set!(key : String | Symbol, value : Nil, *attributes, &)

nil-коллекция с блоком → [] (Ruby: array! nil → [])

Source
set!(key : String | Symbol, &)
Source
set!(key : String | Symbol, value, *attributes)
Source
target!

target! — JSON-строка.

Source

Macros

method_missing(call)

method_missing → set! (json.name "David" — 1:1 к Ruby, где method_missing = set!). DSL-методы (set!/array!/extract!/call) — обычные def-методы и находятся напрямую, сюда попадают только произвольные имена ключей. Аргументы приходят переименованными (_arg0) и обрабатываются на этапе выполнения.

Source

Nested types