Class: Moniker::Domain

Inherits:
Common show all
Defined in:
lib/moniker/domain.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) ⇒ Domain

:notnew:



49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/moniker/domain.rb', line 49

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

  super(new_attributes, persisted)
end

Class Method Details

.find_all_by_email(email, options = {}) ⇒ Object



85
86
87
# File 'lib/moniker/domain.rb', line 85

def self.find_all_by_email(email, options = {})
  all(options).select { |domain| domain.email == email }
end

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



81
82
83
# File 'lib/moniker/domain.rb', line 81

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

Instance Method Details

#encode(options = {}) ⇒ Object

Overloads ActiveRecord::encode method



65
66
67
68
69
70
71
72
73
74
75
# File 'lib/moniker/domain.rb', line 65

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

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

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

#recordsObject



77
78
79
# File 'lib/moniker/domain.rb', line 77

def records
  persisted? ? Record.find(:all, :domain_id => id) : []
end