Class: VersionOne::Meta
- Inherits:
-
Object
- Object
- VersionOne::Meta
- Defined in:
- lib/version-one/meta.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
- .cache ⇒ Object
- .cache=(c) ⇒ Object
- .get(asset_type, client = nil) ⇒ Object
- .get_cached(asset_type) ⇒ Object
- .set_cached(asset_type, meta) ⇒ Object
Instance Method Summary collapse
- #[](name) ⇒ Object
-
#initialize(xml) ⇒ Meta
constructor
A new instance of Meta.
- #inspect ⇒ Object
Constructor Details
#initialize(xml) ⇒ Meta
Returns a new instance of Meta.
10 11 12 |
# File 'lib/version-one/meta.rb', line 10 def initialize(xml) parse_xml(xml) end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
8 9 10 |
# File 'lib/version-one/meta.rb', line 8 def attributes @attributes end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/version-one/meta.rb', line 7 def name @name end |
Class Method Details
.cache ⇒ Object
26 27 28 |
# File 'lib/version-one/meta.rb', line 26 def self.cache @@cache ||= nil end |
.cache=(c) ⇒ Object
30 31 32 |
# File 'lib/version-one/meta.rb', line 30 def self.cache=(c) @@cache = c end |
.get(asset_type, client = nil) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/version-one/meta.rb', line 14 def self.get(asset_type, client=nil) xml = get_cached(asset_type) unless xml client ||= VersionOne::Client.new xml = client.get('/meta.v1/' + asset_type) set_cached(asset_type, xml) end new(xml) end |
.get_cached(asset_type) ⇒ Object
59 60 61 62 63 64 65 66 67 |
# File 'lib/version-one/meta.rb', line 59 def self.get_cached(asset_type) if cache xml = XML::Document.string(cache.read("VersionOne/Meta/#{asset_type}")).root rescue nil VersionOne.logger.debug("Loaded #{asset_type} meta from cache") if xml xml else nil end end |
.set_cached(asset_type, meta) ⇒ Object
69 70 71 |
# File 'lib/version-one/meta.rb', line 69 def self.set_cached(asset_type, ) cache.write("VersionOne/Meta/#{asset_type}", .to_s) if cache end |
Instance Method Details
#[](name) ⇒ Object
34 35 36 |
# File 'lib/version-one/meta.rb', line 34 def [](name) @named_attributes[name] end |
#inspect ⇒ Object
38 39 40 |
# File 'lib/version-one/meta.rb', line 38 def inspect '#<Meta:%s>' % [self.name] end |