Module: OnStomp::Interfaces::UriConfigurable::ClassMethods
- Defined in:
- lib/onstomp/interfaces/uri_configurable.rb
Overview
Provides attribute methods that can be configured by URI attributes or query parameters.
Instance Method Summary collapse
-
#attr_configurable(*args, &block) ⇒ Object
Creates a group readable and writeable attributes that can be set by a URI query parameter sharing the same name, a property of a URI or a default value.
-
#attr_configurable_arr(*args, &block) ⇒ Object
Creates a group readable and writeable attributes that can be set by a URI query parameter sharing the same name, a property of a URI or a default value.
-
#attr_configurable_class(*args, &block) ⇒ Object
Creates a group readable and writeable attributes that can be set by a URI query parameter sharing the same name, a property of a URI or a default value.
-
#attr_configurable_single(*args, &block) ⇒ Object
Creates a group readable and writeable attributes that can be set by a URI query parameter sharing the same name, a property of a URI or a default value.
-
#attr_configurable_str(*args, &block) ⇒ Object
Creates a group readable and writeable attributes that can be set by a URI query parameter sharing the same name, a property of a URI or a default value.
Instance Method Details
#attr_configurable(*args, &block) ⇒ Object
Creates a group readable and writeable attributes that can be set by a URI query parameter sharing the same name, a property of a URI or a default value. The value of this attribute will be transformed by invoking the given block, if one has been provided.
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/onstomp/interfaces/uri_configurable.rb', line 29 def attr_configurable *args, &block opts = args.last.is_a?(Hash) ? args.pop : {} args.each do |attr_name| init_config_attribute attr_name, opts attr_reader attr_name define_method :"#{attr_name}=" do |v| instance_variable_set(:"@#{attr_name}", (block ? block.call(v) : v)) end end end |
#attr_configurable_arr(*args, &block) ⇒ Object
Creates a group readable and writeable attributes that can be set by a URI query parameter sharing the same name, a property of a URI or a default value. The value of this attribute will be transformed by invoking the given block, if one has been provided. If the attributes created by this method are assigned a value that is not an Array, the value will be wrapped in an array.
68 69 70 71 |
# File 'lib/onstomp/interfaces/uri_configurable.rb', line 68 def attr_configurable_arr *args, &block trans = attr_configurable_wrap lambda { |v| Array(v) }, block attr_configurable(*args, &trans) end |
#attr_configurable_class(*args, &block) ⇒ Object
Creates a group readable and writeable attributes that can be set by a URI query parameter sharing the same name, a property of a URI or a default value. The value of this attribute will be transformed by invoking the given block, if one has been provided. The attributes created by this method will be treated as though they were created with #attr_configurable_single and will also be converted into Class or Module objects.
80 81 82 83 |
# File 'lib/onstomp/interfaces/uri_configurable.rb', line 80 def attr_configurable_class *args, &block trans = attr_configurable_wrap lambda { |v| OnStomp.constantize(v) }, block attr_configurable_single(*args, &trans) end |
#attr_configurable_single(*args, &block) ⇒ Object
Creates a group readable and writeable attributes that can be set by a URI query parameter sharing the same name, a property of a URI or a default value. The value of this attribute will be transformed by invoking the given block, if one has been provided. If the attributes created by this method are assigned an Array, only the first element will be used as their value.
46 47 48 49 |
# File 'lib/onstomp/interfaces/uri_configurable.rb', line 46 def attr_configurable_single *args, &block trans = attr_configurable_wrap lambda { |v| v.is_a?(Array) ? v.first : v }, block attr_configurable(*args, &trans) end |
#attr_configurable_str(*args, &block) ⇒ Object
Creates a group readable and writeable attributes that can be set by a URI query parameter sharing the same name, a property of a URI or a default value. The value of this attribute will be transformed by invoking the given block, if one has been provided. The attributes created by this method will be treated as though they were created with #attr_configurable_single and will also be converted into Strings.
57 58 59 60 |
# File 'lib/onstomp/interfaces/uri_configurable.rb', line 57 def attr_configurable_str *args, &block trans = attr_configurable_wrap lambda { |v| v.to_s }, block attr_configurable_single(*args, &trans) end |