Module: MQTT::Homie::HomieAttribute::ClassMethods
- Defined in:
- lib/mqtt/homie/homie_attribute.rb
Instance Method Summary collapse
- #homie_attr(name, options = {}) ⇒ Object
- #homie_attr_list ⇒ Object
- #homie_attr_options(name) ⇒ Object
- #homie_has_id? ⇒ Boolean
- #homie_id ⇒ Object
Instance Method Details
#homie_attr(name, options = {}) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/mqtt/homie/homie_attribute.rb', line 10 def homie_attr(name, = {}) # define accessors attr_reader name unless [:immutable] define_method("#{name}=") { |value| homie_attr_set(name, value) } end # record attribute data @homie_attribute_list ||= [] @homie_attribute_list << [name.to_sym, ] end |
#homie_attr_list ⇒ Object
31 32 33 |
# File 'lib/mqtt/homie/homie_attribute.rb', line 31 def homie_attr_list @homie_attribute_list || [] end |
#homie_attr_options(name) ⇒ Object
35 36 37 38 |
# File 'lib/mqtt/homie/homie_attribute.rb', line 35 def (name) data = homie_attr_list.find { |i| i[0] == name } || [] data[1] || {} end |
#homie_has_id? ⇒ Boolean
27 28 29 |
# File 'lib/mqtt/homie/homie_attribute.rb', line 27 def homie_has_id? !!homie_attr_list.detect { |i| i[0] == :id } end |
#homie_id ⇒ Object
23 24 25 |
# File 'lib/mqtt/homie/homie_attribute.rb', line 23 def homie_id homie_attr :id, required: true, validate: lambda { |i| valid_id?(i) }, immutable: true, hidden: true end |