Class: JIRA::Entity Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/jiraSOAP/entities/entity.rb

Overview

This class is abstract.

The base class for all JIRA objects that can given by the server.

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.parseHash{String=>Array(Symbol,Symbol,Class*)}

Used for parsing XML

Returns:

  • (Hash{String=>Array(Symbol,Symbol,Class*)})


11
12
13
# File 'lib/jiraSOAP/entities/entity.rb', line 11

def parse
  @parse
end

Class Method Details

.add_attribute(name, jira_name, transformer) ⇒ nil

TODO:

Add a way to signify if an attribute should not be used in message building, as some attributes should never be included in a SOAP message.

Define a single instance attribute on the class including the specification on how to parse the XML output and how to build SOAP messages.

Predicate methods will automatically be created if the transformer method is :to_boolean.

Parameters:

  • name (Symbol)

    name of the attribute to create

  • jira_name (String)

    name of the XML tag to look for when parsing responses from the server

  • transformer (Symbol, Array(Symbol,Class))

    either the method name to transform some XML contents, or the method name and the class to build from the attribute

Returns:

  • (nil)


39
40
41
42
43
# File 'lib/jiraSOAP/entities/entity.rb', line 39

def add_attribute name, jira_name, transformer
  attr_accessor name
  alias_method "#{name}?", name if transformer == :to_boolean
  @parse[jira_name] = [:"#{name}=", *transformer]
end

.inherited(subclass) ⇒ Object

Define the callback to automatically initialize the build and parse tables when any subclass is defined.



16
17
18
# File 'lib/jiraSOAP/entities/entity.rb', line 16

def inherited subclass
  subclass.parse = @parse.dup
end

.new_with_xml(frag) ⇒ JIRA::Entity



51
52
53
54
55
# File 'lib/jiraSOAP/entities/entity.rb', line 51

def self.new_with_xml frag
  entity = allocate
  entity.initialize_with_xml frag
  entity
end

Instance Method Details

#initialize_with_xml(element) ⇒ Object

Parameters:



58
59
60
61
62
63
64
65
# File 'lib/jiraSOAP/entities/entity.rb', line 58

def initialize_with_xml element
  attributes = self.class.parse
  element.children.each { |node|
    action = attributes[node.name]
    self.send action[0], (node.send *action[1..-1]) if action
    #puts "Action is #{action.inspect} for #{node.node_name}"
  }
end