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)

Instance Method Details

- (Object) attr_configurable(*args, &block)

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

- (Object) attr_configurable_arr(*args, &block)

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

- (Object) attr_configurable_class(*args, &block)

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.



87
88
89
90
# File 'lib/onstomp/interfaces/uri_configurable.rb', line 87

def attr_configurable_class *args, &block
  trans = attr_configurable_wrap lambda { |v| OnStomp.constantize(v) }, block
  attr_configurable_single(*args, &trans)
end

- (Object) attr_configurable_int(*args, &block)

Creates readable and writeable attributes that are automatically converted into integers.



75
76
77
78
# File 'lib/onstomp/interfaces/uri_configurable.rb', line 75

def attr_configurable_int *args, &block
  trans = attr_configurable_wrap lambda { |v| v.to_i }, block
  attr_configurable_single(*args, &trans)
end

- (Object) attr_configurable_single(*args, &block)

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

- (Object) attr_configurable_str(*args, &block)

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