Class: Moniker::Record

Inherits:
Common show all
Defined in:
lib/moniker/record.rb

Overview

A Moniker Domain

Attributes

  • name - Name of this image

  • email - e-mail of the registrant

  • ttl - domain ttl

  • serial - domain serial

  • updated_at - Modification date

  • created_at - Creation date

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Common

collection_path, custom_method_collection_url, element_path

Methods inherited from Base

headers, site, site=

Methods inherited from ActiveResource::Base

#load

Constructor Details

#initialize(attributes = {}, persisted = false) ⇒ Record

:notnew:



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/moniker/record.rb', line 59

def initialize(attributes = {}, persisted = false) # :notnew:
  attributes = attributes.with_indifferent_access
  new_attributes = {
      :id => attributes[:id],
      :name => attributes[:name],
      :type => attributes[:type],
      :domain_id => attributes[:domain_id],
      :ttl => attributes[:ttl].present? ? attributes[:ttl].to_i : nil,
      :priority => attributes[:priority].present? ? attributes[:priority].to_i : nil,
      :data => attributes[:data],
      :updated_at => attributes[:created_at].present? ? DateTime.strptime(attributes[:created_at], Moniker::DATETIME_FORMAT) : nil,
      :created_at => attributes[:created_at].present? ? DateTime.strptime(attributes[:created_at], Moniker::DATETIME_FORMAT) : nil
  }

  super(new_attributes, persisted)
end

Class Method Details

.find_all_by_data(data, options = {}) ⇒ Object



118
119
120
# File 'lib/moniker/record.rb', line 118

def self.find_all_by_data(data, options = {})
  all(options).select { |record| record.data == data }
end

.find_all_by_name(name, options = {}) ⇒ Object



110
111
112
# File 'lib/moniker/record.rb', line 110

def self.find_all_by_name(name, options = {})
  all(options).select { |record| record.name == name }
end

.find_all_by_type(type, options = {}) ⇒ Object



114
115
116
# File 'lib/moniker/record.rb', line 114

def self.find_all_by_type(type, options = {})
  all(options).select { |record| record.type == type }
end

.find_by_name(name, options = {}) ⇒ Object



106
107
108
# File 'lib/moniker/record.rb', line 106

def self.find_by_name(name, options = {})
  all(options).detect { |record| record.name == name }
end

Instance Method Details

#domainObject



99
100
101
102
103
104
# File 'lib/moniker/record.rb', line 99

def domain
  domain_id.present? ? (Domain.find domain_id) : nil
rescue ActiveResource::ResourceNotFound => e

  nil
end

#domain_idObject



95
96
97
# File 'lib/moniker/record.rb', line 95

def domain_id
  @prefix_options[:domain_id]
end

#encode(options = {}) ⇒ Object

Overloads ActiveRecord::encode method

Parameters:

  • options (Object) (defaults to: {})


78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/moniker/record.rb', line 78

def encode(options={}) # :nodoc: Custom encoding to deal with moniker API
  to_encode = {
      :name => name,
      :type => type,
      :data => data
  }

  to_encode[:ttl] = ttl if ttl.present?
  to_encode[:priority] = priority if priority.present?

  to_encode.send("to_#{self.class.format.extension}", options)
end

#update_attributes(attributes) ⇒ Object



91
92
93
# File 'lib/moniker/record.rb', line 91

def update_attributes(attributes)
  super attributes.merge @prefix_options
end