Class: BottledService
- Inherits:
-
Object
- Object
- BottledService
- Defined in:
- lib/bottled_services/bottled_service.rb
Defined Under Namespace
Classes: BottledServiceError, IllegalTypeError
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(**atts) ⇒ BottledService
constructor
A new instance of BottledService.
Constructor Details
#initialize(**atts) ⇒ BottledService
Returns a new instance of BottledService.
26 27 28 29 30 |
# File 'lib/bottled_services/bottled_service.rb', line 26 def initialize(**atts) atts.each do |key, value| self.send("#{key}=", value) end end |
Class Method Details
.att(att_key, type = nil) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/bottled_services/bottled_service.rb', line 2 def self.att(att_key, type=nil) unless type.nil? define_method "#{att_key}=" do |value| raise IllegalTypeError unless value.is_a?(type) instance_variable_set "@#{att_key}", value end else define_method "#{att_key}=" do |value| instance_variable_set "@#{att_key}", value end end define_method att_key do instance_variable_get "@#{att_key}" end end |
.call(**atts) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/bottled_services/bottled_service.rb', line 18 def self.call(**atts) if block_given? new(**atts).(&Proc.new) else new(**atts).() end end |