Class: Dslimple::Query
- Inherits:
-
Object
- Object
- Dslimple::Query
- Defined in:
- lib/dslimple/query.rb
Instance Attribute Summary collapse
-
#operation ⇒ Object
readonly
Returns the value of attribute operation.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
-
#zone ⇒ Object
readonly
Returns the value of attribute zone.
Instance Method Summary collapse
- #execute(api_client, account) ⇒ Object
- #execute_record(api_client, account_id) ⇒ Object
- #execute_zone(api_client, account_id) ⇒ Object
-
#initialize(operation, target, zone, params = {}) ⇒ Query
constructor
A new instance of Query.
- #record_options ⇒ Object
- #to_s ⇒ Object
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
#operation ⇒ Object (readonly)
Returns the value of attribute operation.
4 5 6 |
# File 'lib/dslimple/query.rb', line 4 def operation @operation end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
4 5 6 |
# File 'lib/dslimple/query.rb', line 4 def params @params end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
4 5 6 |
# File 'lib/dslimple/query.rb', line 4 def target @target end |
#zone ⇒ Object (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, account) __send__("execute_#{target}", api_client, account) 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, account_id) case operation when :addition api_client.zones.create_zone_record(account_id, zone, params) when :modification api_client.zones.update_zone_record(account_id, zone, params[:id], params) when :deletion api_client.zones.delete_zone_record(account_id, 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, account_id) 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_options ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/dslimple/query.rb', line 29 def = [] params.each_pair do |k, v| << "#{k}: #{v}" if %i(ttl priority regions).include?(k) && v end end |
#to_s ⇒ Object
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} (#{.join(', ')}) "#{params[:content]}") end end |