Class: ParamsReady::Parameter::AbstractStructParameter
Constant Summary
collapse
- EMPTY_HASH =
'0'
Instance Attribute Summary
#definition
Instance Method Summary
collapse
#update_child
Methods inherited from Parameter
#allows_undefined?, #definite_default?, #eligible_for_output?, #format, #format_self_permitted, #freeze, #hash, #hash_key, #initialize, #inspect_content, #is_default?, #is_definite?, #is_nil?, #is_undefined?, #memo, #memo!, #nil_default?, #populate_other, #set_from_input, #set_value, #to_hash_if_eligible, #unwrap, #unwrap_or
#==, #dup, #initialize, #inspect, intent_for_children, #match?, #populate, #to_hash, #update_if_applicable, #update_in
#freeze_variable, #freeze_variables, #variables_to_freeze
Methods included from FromHash
#set_from_hash
#freeze
Instance Method Details
#[](name) ⇒ Object
33
34
35
|
# File 'lib/params_ready/parameter/abstract_struct_parameter.rb', line 33
def [](name)
child(name)
end
|
#[]=(name, value) ⇒ Object
27
28
29
30
31
|
# File 'lib/params_ready/parameter/abstract_struct_parameter.rb', line 27
def []=(name, value)
init_for_write
c = child(name)
c.set_value(value)
end
|
#find_in_hash(hash, context) ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/params_ready/parameter/abstract_struct_parameter.rb', line 37
def find_in_hash(hash, context)
found, result = super hash, context
if !(default_defined? || optional?) && result == Extensions::Undefined
[true, {}]
elsif result == EMPTY_HASH
[true, {}]
else
[found, result]
end
end
|
#for_frontend(format = :frontend, restriction: nil, data: nil) ⇒ Object
68
69
70
|
# File 'lib/params_ready/parameter/abstract_struct_parameter.rb', line 68
def for_frontend(format = :frontend, restriction: nil, data: nil)
for_output(format, restriction: restriction, data: data)
end
|
#for_model(format = :update, restriction: nil) ⇒ Object
72
73
74
|
# File 'lib/params_ready/parameter/abstract_struct_parameter.rb', line 72
def for_model(format = :update, restriction: nil)
for_output(format, restriction: restriction)
end
|
#for_output(format, restriction: nil, data: nil) ⇒ Object
59
60
61
62
63
64
65
66
|
# File 'lib/params_ready/parameter/abstract_struct_parameter.rb', line 59
def for_output(format, restriction: nil, data: nil)
restriction ||= Restriction.blanket_permission
intent = Intent.new(format, restriction, data: data)
output = format(intent)
return {} if output.nil? || output == EMPTY_HASH
output
end
|
#wrap_output(output, intent) ⇒ Object
51
52
53
54
55
56
57
|
# File 'lib/params_ready/parameter/abstract_struct_parameter.rb', line 51
def wrap_output(output, intent)
if (output.nil? || output.empty?) && !default_defined? && !optional?
nil
else
super
end
end
|