Class: AttrHelper::RequiredAttr
- Defined in:
- lib/attr_helper/required_attr.rb
Instance Attribute Summary collapse
-
#if_cond ⇒ Object
readonly
Returns the value of attribute if_cond.
-
#unless_cond ⇒ Object
readonly
Returns the value of attribute unless_cond.
Attributes inherited from BaseAttr
#default, #key, #name, #serialize
Instance Method Summary collapse
-
#initialize(name, options = {}) ⇒ RequiredAttr
constructor
A new instance of RequiredAttr.
- #required?(parent) ⇒ Boolean
Methods inherited from BaseAttr
Constructor Details
#initialize(name, options = {}) ⇒ RequiredAttr
Returns a new instance of RequiredAttr.
6 7 8 9 10 |
# File 'lib/attr_helper/required_attr.rb', line 6 def initialize(name, = {}) super(name, ) @if_cond = [:if] @unless_cond = [:unless] end |
Instance Attribute Details
#if_cond ⇒ Object (readonly)
Returns the value of attribute if_cond.
3 4 5 |
# File 'lib/attr_helper/required_attr.rb', line 3 def if_cond @if_cond end |
#unless_cond ⇒ Object (readonly)
Returns the value of attribute unless_cond.
4 5 6 |
# File 'lib/attr_helper/required_attr.rb', line 4 def unless_cond @unless_cond end |
Instance Method Details
#required?(parent) ⇒ Boolean
12 13 14 15 16 17 18 |
# File 'lib/attr_helper/required_attr.rb', line 12 def required?(parent) if conditions_empty? true else included?(parent) && !excluded?(parent) end end |