Class: Dslimple::Query

Inherits:
Object
  • Object
show all
Defined in:
lib/dslimple/query.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(operation, target, zone, params = {}) ⇒ Query

Returns a new instance of Query.



6
7
8
9
10
11
# File 'lib/dslimple/query.rb', line 6

def initialize(operation, target, zone, params = {})
  @operation = operation
  @target = target
  @zone = zone
  @params = params
end

Instance Attribute Details

#operationObject (readonly)

Returns the value of attribute operation.



4
5
6
# File 'lib/dslimple/query.rb', line 4

def operation
  @operation
end

#paramsObject (readonly)

Returns the value of attribute params.



4
5
6
# File 'lib/dslimple/query.rb', line 4

def params
  @params
end

#targetObject (readonly)

Returns the value of attribute target.



4
5
6
# File 'lib/dslimple/query.rb', line 4

def target
  @target
end

#zoneObject (readonly)

Returns the value of attribute zone.



4
5
6
# File 'lib/dslimple/query.rb', line 4

def zone
  @zone
end

Instance Method Details

#execute(api_client, account) ⇒ Object



37
38
39
# File 'lib/dslimple/query.rb', line 37

def execute(api_client, )
  __send__("execute_#{target}", api_client, )
end

#execute_record(api_client, account_id) ⇒ Object



52
53
54
55
56
57
58
59
60
61
# File 'lib/dslimple/query.rb', line 52

def execute_record(api_client, )
  case operation
  when :addition
    api_client.zones.create_zone_record(, zone, params)
  when :modification
    api_client.zones.update_zone_record(, zone, params[:id], params)
  when :deletion
    api_client.zones.delete_zone_record(, zone, params[:id])
  end
end

#execute_zone(api_client, account_id) ⇒ Object



41
42
43
44
45
46
47
48
49
50
# File 'lib/dslimple/query.rb', line 41

def execute_zone(api_client, )
  case operation
  when :addition
    # TODO: Support registration
    # api_client.registrar.register_zone(account_id, zone, registrant_id: account.id, auto_renew: true)
  when :deletion
    # TODO: Support deletion
    # api_client.zones.delete_zone(account_id, zone)
  end
end

#record_optionsObject



29
30
31
32
33
34
35
# File 'lib/dslimple/query.rb', line 29

def record_options
  options = []
  params.each_pair do |k, v|
    options << "#{k}: #{v}" if %i(ttl priority regions).include?(k) && v
  end
  options
end

#to_sObject



21
22
23
24
25
26
27
# File 'lib/dslimple/query.rb', line 21

def to_s
  if target == :zone
    zone.to_s
  else
    %(#{params[:type].to_s.rjust(5)} #{params[:name].to_s.rjust(10)}.#{zone.to_s} (#{record_options.join(', ')}) "#{params[:content]}")
  end
end