Module: Reactor::XmlAttributes::ClassMethods

Defined in:
lib/reactor/tools/xml_attributes.rb

Instance Method Summary collapse

Instance Method Details

#attribute(name, options = {}) ⇒ Object



33
34
35
36
37
38
39
40
41
42
# File 'lib/reactor/tools/xml_attributes.rb', line 33

def attribute(name, options = {})
  xml_name = options.delete(:name).presence || name
  type = options.delete(:type).presence

  attribute = Reactor::Cm::XmlAttribute.new(xml_name, type, options)

  self._attributes[name.to_sym] = attribute

  attr_accessor name
end

#attribute_namesObject



63
64
65
# File 'lib/reactor/tools/xml_attributes.rb', line 63

def attribute_names
  self._attributes.keys
end

#attributes(scopes = []) ⇒ Object



44
45
46
47
48
49
50
51
52
53
# File 'lib/reactor/tools/xml_attributes.rb', line 44

def attributes(scopes = [])
  scopes = Array(scopes)
  attributes = self._attributes

  if scopes.present?
    attributes.reject { |_, xml_attribute| (xml_attribute.scopes & scopes).blank? }
  else
    attributes
  end
end

#primary_key(new_value = nil) ⇒ Object

This method can act as both getter and setter. I admit, that it is not the best design ever. But it makes a pretty good DSL



24
25
26
27
28
29
30
31
# File 'lib/reactor/tools/xml_attributes.rb', line 24

def primary_key(new_value = nil)
  if new_value.nil?
    @primary_key
  else
    @primary_key = new_value.to_s
    @primary_key
  end
end

#xml_attribute(name) ⇒ Object



55
56
57
# File 'lib/reactor/tools/xml_attributes.rb', line 55

def xml_attribute(name)
  self._attributes[name.to_sym]
end

#xml_attribute_namesObject



59
60
61
# File 'lib/reactor/tools/xml_attributes.rb', line 59

def xml_attribute_names
  self._attributes.values.map(&:name)
end