Skip to content

Commit

Permalink
feat: add a few extra helper methods
Browse files Browse the repository at this point in the history
  • Loading branch information
adamcooke committed Apr 19, 2021
1 parent b457cff commit dac9ccb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ group.nameservers
# Get all tagged records for a group
group.tagged_records(['tag1'])

# Lookup a zone within a group
group.zone(1)
group.zone('test.com', field: :name)

# Create a new zone
zone = group.create_zone('example.com')

Expand Down
12 changes: 10 additions & 2 deletions lib/dennis/group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,16 @@ def create_or_update_zone(**properties)
Zone.create_or_update(@client, group: { id: id }, **properties)
end

def zones
Zone.all_for_group(@client, { id: id })
def zones(**options)
Zone.all_for_group(@client, { id: id }, **options)
end

def zone(id, field: :id)
zone = Zone.find_by(@client, field, id)
return nil if zone.nil?
return nil if zone.group.id != self.id

zone
end

def tagged_records(tags)
Expand Down
11 changes: 9 additions & 2 deletions lib/dennis/zone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,13 @@ def default_ttl
@hash['default_ttl']
end

def group
return @group if @group
return nil unless @hash['group']

@group = Group.new(@client, @hash['group'])
end

def created_at
return nil if @hash['created_at'].nil?
return @hash['created_at'] if @hash['created_at'].is_a?(Time)
Expand All @@ -146,8 +153,8 @@ def create_or_update_record(**properties)
Record.create_or_update(@client, id, **properties)
end

def records
Record.all(@client, { id: id })
def records(**options)
Record.all(@client, { id: id }, **options)
end

def update(properties)
Expand Down

0 comments on commit dac9ccb

Please sign in to comment.