Class: AMEE::Object
- Inherits:
-
Object
- Object
- AMEE::Object
- Extended by:
- ParseHelper
- Includes:
- ParseHelper
- Defined in:
- lib/amee/object.rb
Direct Known Subclasses
Admin::ItemDefinition, Admin::ItemValueDefinition, Admin::ReturnValueDefinition, Admin::User, Data::Object, Profile::Object
Instance Attribute Summary collapse
-
#connection ⇒ Object
Returns the value of attribute connection.
-
#created ⇒ Object
readonly
Returns the value of attribute created.
-
#modified ⇒ Object
readonly
Returns the value of attribute modified.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#uid ⇒ Object
readonly
Returns the value of attribute uid.
Class Method Summary collapse
-
.get_and_parse(connection, path, options) ⇒ Object
A nice shared get/parse handler that handles retry on parse errors.
Instance Method Summary collapse
- #expire_cache ⇒ Object
-
#initialize(data = nil) ⇒ Object
constructor
A new instance of Object.
Methods included from ParseHelper
load_xml_doc, node_value, xmlpathpreamble
Constructor Details
#initialize(data = nil) ⇒ Object
Returns a new instance of Object.
8 9 10 11 12 13 14 15 |
# File 'lib/amee/object.rb', line 8 def initialize(data = nil) @uid = data ? data[:uid] : nil @created = data ? data[:created] : Time.now @modified = data ? data[:modified] : @created @path = data ? data[:path] : nil @name = data ? data[:name] : nil @connection = data ? data[:connection] : nil end |
Instance Attribute Details
#connection ⇒ Object
Returns the value of attribute connection.
17 18 19 |
# File 'lib/amee/object.rb', line 17 def connection @connection end |
#created ⇒ Object (readonly)
Returns the value of attribute created.
19 20 21 |
# File 'lib/amee/object.rb', line 19 def created @created end |
#modified ⇒ Object (readonly)
Returns the value of attribute modified.
20 21 22 |
# File 'lib/amee/object.rb', line 20 def modified @modified end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
22 23 24 |
# File 'lib/amee/object.rb', line 22 def name @name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
21 22 23 |
# File 'lib/amee/object.rb', line 21 def path @path end |
#uid ⇒ Object (readonly)
Returns the value of attribute uid.
18 19 20 |
# File 'lib/amee/object.rb', line 18 def uid @uid end |
Class Method Details
.get_and_parse(connection, path, options) ⇒ Object
A nice shared get/parse handler that handles retry on parse errors
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/amee/object.rb', line 29 def self.get_and_parse(connection, path, ) # Note that we don't check the number of times retry has been done lower down # and count separately instead. # Worst case could be retries squared given the right pattern of failure, but # that seems unlikely. Would need, for instance, repeated 503 503 200->parse_fail retries = [1] * connection.retries begin # Load data from path response = connection.get(path, ).body # Parse data from response if response.is_json? from_json(response) else from_xml(response) end rescue JSON::ParserError, Nokogiri::XML::SyntaxError, REXML::ParseException => e # Invalid JSON or XML received, try the GET again in case it got cut off mid-stream connection.expire(path) if delay = retries.shift sleep delay retry else raise end rescue AMEE::BadData connection.expire(path) raise end end |
Instance Method Details
#expire_cache ⇒ Object
24 25 26 |
# File 'lib/amee/object.rb', line 24 def expire_cache @connection.expire_matching(full_path+'.*') end |