Class: EZDyn::Zone
- Inherits:
-
Object
- Object
- EZDyn::Zone
- Defined in:
- lib/ezdyn/zone.rb
Overview
Abstraction of Dyn REST API DNS Zones
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#serial ⇒ Object
readonly
Returns the serial number of the zone.
-
#serial_style ⇒ Object
readonly
Returns the style of serial number in use by this zone.
-
#type ⇒ Object
readonly
Returns the zone type.
Instance Method Summary collapse
-
#in_sync? ⇒ Boolean
Indicates whether the object has been synced with the API.
-
#initialize(client:, name: nil, type: nil, serial: nil, serial_style: nil, raw: nil, uri: nil) ⇒ Zone
constructor
A new instance of Zone.
-
#sync! ⇒ Object
Attempt to sync the object with the API.
- #sync_raw(raw) ⇒ Object
-
#to_s ⇒ Object
Returns the name of the zone for display purposes.
- #uri ⇒ Object
Constructor Details
#initialize(client:, name: nil, type: nil, serial: nil, serial_style: nil, raw: nil, uri: nil) ⇒ Zone
Returns a new instance of Zone.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/ezdyn/zone.rb', line 7 def initialize(client:, name: nil, type: nil, serial: nil, serial_style: nil, raw: nil, uri: nil) EZDyn.debug { "Zone.new( client: Client{}, name: #{name}, type: #{type}, serial: #{serial}, serial_style: #{serial_style}, raw: #{raw.nil? ? nil : raw.to_json}, uri: #{uri} )" } @client = client @name = name @type = type @serial = serial @serial_style = serial_style @in_sync = false if not raw.nil? self.sync_raw(raw) end if not uri.nil? uri.gsub!(%r{^/?(REST/)?}, '') if uri =~ %r{^Zone/([^/]+)/?$} @name = $1 end end end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/ezdyn/zone.rb', line 4 def name @name end |
#serial ⇒ Object (readonly)
Returns the serial number of the zone.
35 36 37 |
# File 'lib/ezdyn/zone.rb', line 35 def serial @serial end |
#serial_style ⇒ Object (readonly)
Returns the style of serial number in use by this zone.
41 42 43 |
# File 'lib/ezdyn/zone.rb', line 41 def serial_style @serial_style end |
#type ⇒ Object (readonly)
Returns the zone type.
29 30 31 |
# File 'lib/ezdyn/zone.rb', line 29 def type @type end |
Instance Method Details
#in_sync? ⇒ Boolean
Indicates whether the object has been synced with the API.
52 53 54 |
# File 'lib/ezdyn/zone.rb', line 52 def in_sync? @in_sync end |
#sync! ⇒ Object
Attempt to sync the object with the API.
59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/ezdyn/zone.rb', line 59 def sync! EZDyn.debug { "Zone{#{self.name}}.sync!" } return self if self.in_sync? data = @client.fetch_uri_data(uri: self.uri) if data.is_a? Hash sync_raw(data) else raise "Failed to sync zone #{self.name}" end self end |
#sync_raw(raw) ⇒ Object
74 75 76 77 78 79 80 81 |
# File 'lib/ezdyn/zone.rb', line 74 def sync_raw(raw) EZDyn.debug { "Zone{#{self.name}}.sync_raw( #{raw.nil? ? nil : raw.to_json} )" } @name = raw["zone"] @type = raw["zone_type"] @serial = raw["serial"] @serial_style = raw["serial_style"] @in_sync = true end |
#to_s ⇒ Object
Returns the name of the zone for display purposes.
84 85 86 |
# File 'lib/ezdyn/zone.rb', line 84 def to_s self.name end |
#uri ⇒ Object
47 48 49 |
# File 'lib/ezdyn/zone.rb', line 47 def uri "/Zone/#{self.name}" end |