# File lib/reactor/tools/xml_attributes.rb, line 23 def primary_key(new_value = nil) if new_value.nil? @primary_key else @primary_key = new_value.to_s @primary_key end end
module Reactor::XmlAttributes::ClassMethods
Public Instance Methods
attribute(name, options = {})
click to toggle source
# File lib/reactor/tools/xml_attributes.rb, line 32 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_names()
click to toggle source
# File lib/reactor/tools/xml_attributes.rb, line 62 def attribute_names self._attributes.keys end
attributes(scopes = [])
click to toggle source
# File lib/reactor/tools/xml_attributes.rb, line 43 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)
click to toggle source
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
xml_attribute(name)
click to toggle source
# File lib/reactor/tools/xml_attributes.rb, line 54 def xml_attribute(name) self._attributes[name.to_sym] end
xml_attribute_names()
click to toggle source
# File lib/reactor/tools/xml_attributes.rb, line 58 def xml_attribute_names self._attributes.values.map(&:name) end