module BlackBox::Concern
Include this concern to make your class a black box!
Constants
- BOX_ATTRIBUTES
Attributes
subject[RW]
Public Class Methods
new()
click to toggle source
# File lib/black_box/concern.rb, line 45 def initialize initialize_subject end
Public Instance Methods
accept(*attributes)
click to toggle source
# File lib/black_box/concern.rb, line 25 def accept(*attributes) box_attributes.push(*attributes) box_attributes.uniq! cattr_accessor(*attributes) end
configure() { |self| ... }
click to toggle source
# File lib/black_box/concern.rb, line 38 def configure yield self if block_given? end
expose(*methods)
click to toggle source
# File lib/black_box/concern.rb, line 31 def expose(*methods) box_methods.push(*methods) box_methods.uniq! singleton_class.class_eval { delegate(*methods, to: :instance) } delegate(*methods, to: :subject) end
Private Instance Methods
initialize_params()
click to toggle source
# File lib/black_box/concern.rb, line 49 def initialize_params box_attributes.map do |key| [key, send(key)] end.to_h end
initialize_subject()
click to toggle source
# File lib/black_box/concern.rb, line 55 def initialize_subject self.subject = box_class.new initialize_params end