class ParamsReady::Intent
Attributes
data[R]
hash[R]
Public Class Methods
instance(name)
click to toggle source
# File lib/params_ready/intent.rb, line 47 def self.instance(name) format = Format.instance(name) Intent.new(format) end
new(format, restriction = Restriction.blanket_permission, data: nil)
click to toggle source
# 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
resolve(intent_or_name)
click to toggle source
# 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
Public Instance Methods
==(other)
click to toggle source
# 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)
click to toggle source
# File lib/params_ready/intent.rb, line 27 def check_data(data) return if data.nil? # The reason we require data object to be # a Parameter is that it must be deep frozen # for the output memoizing feature to work properly. 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:)
click to toggle source
# File lib/params_ready/intent.rb, line 12 def clone(restriction:) Intent.new @format, restriction, data: @data end
eql?(other)
click to toggle source
# File lib/params_ready/intent.rb, line 66 def eql?(other) self == other end
omit?(parameter)
click to toggle source
# File lib/params_ready/intent.rb, line 38 def omit?(parameter) return true unless permitted?(parameter) @format.omit?(parameter) end
preserve?(parameter)
click to toggle source
# File lib/params_ready/intent.rb, line 43 def preserve?(parameter) !omit?(parameter) end