Module: Reactor::XmlAttributes::ClassMethods

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

Instance Method Summary collapse

Instance Method Details

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



29
30
31
32
33
34
35
36
37
38
# File 'lib/reactor/tools/xml_attributes.rb', line 29

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)

  _attributes[name.to_sym] = attribute

  attr_accessor name
end

#attribute_namesObject



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

def attribute_names
  _attributes.keys
end

#attributes(scopes = []) ⇒ Object



40
41
42
43
44
45
46
47
48
49
# File 'lib/reactor/tools/xml_attributes.rb', line 40

def attributes(scopes = [])
  scopes = Array(scopes)
  attributes = _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



20
21
22
23
24
25
26
27
# File 'lib/reactor/tools/xml_attributes.rb', line 20

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



51
52
53
# File 'lib/reactor/tools/xml_attributes.rb', line 51

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

#xml_attribute_namesObject



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

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