Class: ParamsReady::Intent
Instance Attribute Summary collapse
#format
#restriction
Class Method Summary
collapse
Instance Method Summary
collapse
#delegate, #for_children, #permit, #permit_all, #prohibit, #to_restriction
Constructor Details
#initialize(format, restriction = Restriction.blanket_permission, data: nil) ⇒ Intent
Returns a new instance of Intent.
18
19
20
21
22
23
24
25
|
# File 'lib/params_ready/intent.rb', line 18
def initialize(format, restriction = Restriction.blanket_permission, data: nil)
@format = Format.resolve(format).freeze
raise ParamsReadyError, "Restriction expected, got: #{restriction.inspect}" unless restriction.is_a? Restriction
@restriction = restriction
@data = check_data(data)
@hash = [@format, @restriction, @data].hash
freeze
end
|
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
16
17
18
|
# File 'lib/params_ready/intent.rb', line 16
def data
@data
end
|
#hash ⇒ Object
Returns the value of attribute hash.
16
17
18
|
# File 'lib/params_ready/intent.rb', line 16
def hash
@hash
end
|
Class Method Details
.instance(name) ⇒ Object
47
48
49
50
|
# File 'lib/params_ready/intent.rb', line 47
def self.instance(name)
format = Format.instance(name)
Intent.new(format)
end
|
.resolve(intent_or_name) ⇒ Object
52
53
54
55
56
57
58
|
# File 'lib/params_ready/intent.rb', line 52
def self.resolve(intent_or_name)
if intent_or_name.is_a? Intent
intent_or_name
else
instance(intent_or_name)
end
end
|
Instance Method Details
#==(other) ⇒ Object
60
61
62
63
64
|
# File 'lib/params_ready/intent.rb', line 60
def ==(other)
return false unless other.is_a?(Intent)
return true if object_id == other.object_id
restriction == other.restriction && format == other.format && data == other.data
end
|
#check_data(data) ⇒ Object
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/params_ready/intent.rb', line 27
def check_data(data)
return if data.nil?
raise 'Data object must be a parameter' unless data.is_a? Parameter::Parameter
raise 'Data object must be frozen' unless data.frozen?
data
end
|
#clone(restriction:) ⇒ Object
12
13
14
|
# File 'lib/params_ready/intent.rb', line 12
def clone(restriction:)
Intent.new @format, restriction, data: @data
end
|
#eql?(other) ⇒ Boolean
66
67
68
|
# File 'lib/params_ready/intent.rb', line 66
def eql?(other)
self == other
end
|
#omit?(parameter) ⇒ Boolean
38
39
40
41
|
# File 'lib/params_ready/intent.rb', line 38
def omit?(parameter)
return true unless permitted?(parameter)
@format.omit?(parameter)
end
|
#preserve?(parameter) ⇒ Boolean
43
44
45
|
# File 'lib/params_ready/intent.rb', line 43
def preserve?(parameter)
!omit?(parameter)
end
|