Class: InspectorGadget::UserPreference

Inherits:
Object
  • Object
show all
Includes:
StickyAttributes
Defined in:
lib/inspectorgadget/user_preference.rb

Instance Method Summary collapse

Methods included from StickyAttributes

#method_missing, #sticky_attributes

Constructor Details

#initialize(properties = {}) ⇒ UserPreference

Returns a new instance of UserPreference.



6
7
8
9
# File 'lib/inspectorgadget/user_preference.rb', line 6

def initialize(properties = {})
  properties.each { |name, value| send name, value } if properties.is_a? Hash
  @enum_values = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class InspectorGadget::StickyAttributes

Instance Method Details

#enum_values(*values) ⇒ Object



11
12
13
14
# File 'lib/inspectorgadget/user_preference.rb', line 11

def enum_values(*values)
  @enum_values = values.flatten unless values.empty?
  @enum_values
end

#is_optionalObject



20
21
22
# File 'lib/inspectorgadget/user_preference.rb', line 20

def is_optional
  self.required = false
end

#is_requiredObject



16
17
18
# File 'lib/inspectorgadget/user_preference.rb', line 16

def is_required
  self.required = true
end

#to_xml(xml) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/inspectorgadget/user_preference.rb', line 24

def to_xml(xml)
  default_vals = sticky_attributes[:default_value].to_a.flatten
  if sticky_attributes[:datatype].to_s == 'list' && !default_vals.empty?
    sticky_attributes[:default_value] = default_vals.join('|')
  end
  
  write_enum_values = proc do
                        enum_values.each do |enum_value|
                          xml.EnumValue :value => enum_value
                        end
                      end
                      
  enum_values.empty?? xml.UserPref(sticky_attributes) : xml.UserPref(sticky_attributes,&write_enum_values)
end