Module: Osb::Internal Private
- Defined in:
- lib/osb/assert.rb,
lib/osb/storyboard.rb,
lib/osb/commandable.rb
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Defined Under Namespace
Classes: LayerManager, TypedArray
Constant Summary collapse
- Boolean =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
[TrueClass, FalseClass]
- T =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
{ Array => { Numeric => TypedArray.new(Numeric) } }
Class Method Summary collapse
-
.assert_file_name_ext!(file_name, exts) ⇒ Object
private
Ensure the file name extenstion is correct.
-
.assert_type!(arg, possible_types, param_name) ⇒ void
private
Check if supplied argument is correctly typed.
-
.assert_value!(arg, possible_values, param_name) ⇒ void
private
Ensures the supplied argument is correct.
- .raise_if_invalid_easing!(easing) ⇒ void private
- .raise_if_invalid_end_time!(time) ⇒ void private
- .raise_if_invalid_start_time!(time) ⇒ void private
Class Method Details
.assert_file_name_ext!(file_name, exts) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Ensure the file name extenstion is correct.
117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/osb/assert.rb', line 117 def self.assert_file_name_ext!(file_name, exts) if exts.is_a?(Array) exts_ = exts.join("|") exts__ = exts.join(" or ") unless /[\w\s\d]+\.(#{exts_})/.match(file_name) raise InvalidValueError, "File name must end with #{exts__}" end else unless /[\w\s\d]+\.#{exts}/.match(file_name) raise InvalidValueError, "File name must end with #{exts}" end end end |
.assert_type!(arg, possible_types, param_name) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Check if supplied argument is correctly typed.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/osb/assert.rb', line 43 def self.assert_type!(arg, possible_types, param_name) if possible_types.is_a?(Array) valid = possible_types.any? do |type| type.is_a?(TypedArray) ? type.valid?(arg) : arg.is_a?(type) end unless valid accepted_types = possible_types.map { |type| type.name }.join(" or ") raise TypeError, "Parameter #{param_name} expects type #{accepted_types}, " + "got type #{arg.class.name} instead." end elsif possible_types.is_a?(TypedArray) valid = possible_types.valid?(arg) unless valid raise TypeError, "Parameter #{param_name} expects type Array<#{possible_types.type.name}>, " + "got type #{arg.class.name} instead." end else type = possible_types unless arg.is_a?(type) raise TypeError, "Parameter #{param_name} expects type #{type.name}, " + "got type #{arg.class.name} instead." end end end |
.assert_value!(arg, possible_values, param_name) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Ensures the supplied argument is correct.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/osb/assert.rb', line 79 def self.assert_value!(arg, possible_values, param_name) val = if arg.is_a?(String) && arg.empty? "an empty string" else arg end if possible_values.is_a?(Array) valid = possible_values.any? { |value| arg == value } unless valid accepted_values = possible_values.join(" or ") raise InvalidValueError, "Parameter #{param_name} expects #{accepted_values}, " + "got #{val} instead." end elsif possible_values.is_a?(Range) valid = arg >= possible_values.min && arg <= possible_values.max unless valid raise InvalidValueError, "Parameter #{param_name} expects value within " + "#{possible_values.min} to #{possible_values.max}, " + "got #{val} instead." end else unless arg == possible_values raise InvalidValueError, "Parameter #{param_name} expects #{possible_values}, " + "got #{val} instead." end end end |
.raise_if_invalid_easing!(easing) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
22 23 24 25 |
# File 'lib/osb/commandable.rb', line 22 def self.raise_if_invalid_easing!(easing) Internal.assert_type!(easing, Integer, "easing") Internal.assert_value!(easing, Easing::ALL, "easing") end |
.raise_if_invalid_end_time!(time) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
15 16 17 |
# File 'lib/osb/commandable.rb', line 15 def self.raise_if_invalid_end_time!(time) Internal.assert_type!(time, Integer, "end_time") end |
.raise_if_invalid_start_time!(time) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
8 9 10 |
# File 'lib/osb/commandable.rb', line 8 def self.raise_if_invalid_start_time!(time) Internal.assert_type!(time, Integer, "start_time") end |