Class: Memorium::RequireAttr
- Inherits:
-
Object
- Object
- Memorium::RequireAttr
- Defined in:
- lib/memorium/require_attr.rb
Defined Under Namespace
Classes: Template
Instance Attribute Summary collapse
-
#attr_name ⇒ Object
readonly
Returns the value of attribute attr_name.
-
#by ⇒ Object
readonly
Returns the value of attribute by.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
- #check_requirements ⇒ Object
-
#initialize(attr_name, by:, value:) ⇒ RequireAttr
constructor
A new instance of RequireAttr.
- #raise_text ⇒ Object
Constructor Details
#initialize(attr_name, by:, value:) ⇒ RequireAttr
Returns a new instance of RequireAttr.
7 8 9 10 11 |
# File 'lib/memorium/require_attr.rb', line 7 def initialize(attr_name, by:, value:) @attr_name = attr_name.to_s @by = by.is_a?(Proc) ? by : by.to_s @value = value end |
Instance Attribute Details
#attr_name ⇒ Object (readonly)
Returns the value of attribute attr_name.
2 3 4 |
# File 'lib/memorium/require_attr.rb', line 2 def attr_name @attr_name end |
#by ⇒ Object (readonly)
Returns the value of attribute by.
2 3 4 |
# File 'lib/memorium/require_attr.rb', line 2 def by @by end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
2 3 4 |
# File 'lib/memorium/require_attr.rb', line 2 def value @value end |
Class Method Details
.caller_location ⇒ Object
5 |
# File 'lib/memorium/require_attr.rb', line 5 def self.caller_location = caller_locations(4, 1).first |
Instance Method Details
#check_requirements ⇒ Object
13 14 15 16 17 |
# File 'lib/memorium/require_attr.rb', line 13 def check_requirements return by.call(value) if by.is_a?(Proc) inverse_type? ? inverse_check_by_type : check_by_type end |
#raise_text ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/memorium/require_attr.rb', line 19 def raise_text @raise_text ||= begin return "Attribute `#{attr_name}` not pass the condition: #{value.inspect}" if by.is_a?(Proc) "Attribute `#{attr_name}` #{raise_verb} be #{unpredicated_type}: #{value.inspect}" end end |