Class: Enumerize::Predicates::Builder
- Inherits:
-
Object
- Object
- Enumerize::Predicates::Builder
- Defined in:
- lib/enumerize/predicates.rb
Instance Method Summary collapse
- #build(klass) ⇒ Object
-
#initialize(attr, options) ⇒ Builder
constructor
A new instance of Builder.
- #names ⇒ Object
- #values ⇒ Object
Constructor Details
#initialize(attr, options) ⇒ Builder
Returns a new instance of Builder.
48 49 50 51 |
# File 'lib/enumerize/predicates.rb', line 48 def initialize(attr, ) @attr = attr @options = .is_a?(Hash) ? : {} end |
Instance Method Details
#build(klass) ⇒ Object
71 72 73 |
# File 'lib/enumerize/predicates.rb', line 71 def build(klass) klass.delegate(*names, to: @attr.name, prefix: @options[:prefix], allow_nil: true) end |
#names ⇒ Object
67 68 69 |
# File 'lib/enumerize/predicates.rb', line 67 def names values.map { |v| "#{v.tr('-', '_')}?" } end |
#values ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/enumerize/predicates.rb', line 53 def values values = @attr.values if @options[:only] values &= Array(@options[:only]).map(&:to_s) end if @options[:except] values -= Array(@options[:except]).map(&:to_s) end values end |