Module: DeviceMap::Properties::DSL
- Included in:
- DeviceData::Device
- Defined in:
- lib/device_map/properties/dsl.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.included(base) ⇒ Object
18 19 20 |
# File 'lib/device_map/properties/dsl.rb', line 18 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#==(other) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/device_map/properties/dsl.rb', line 34 def ==(other) properties.all? do |_, property| attr_name = property.name public_send(attr_name) == other.public_send(attr_name) end end |
#initialize(attrs) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/device_map/properties/dsl.rb', line 22 def initialize(attrs) attrs.each do |name, value| property = properties.fetch(name.to_sym) do fail UnknownProperty, "Property #{name} is not defined" end attr_name = property.name casted_value = property.cast(value) instance_variable_set(:"@#{attr_name}", casted_value) end end |