Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Kong::Consumer.list(filters)
Kong::Consumer.all()
Kong::Consumer.find(id)
Kong::Consumer.find_by_*(value)
Kong::Consumer.find_all_by_*(value)
Kong::Consumer.create(attributes)

consumer = Kong::Consumer.new({ username: 'test-user' })
Expand Down Expand Up @@ -262,7 +263,8 @@ consumer.jwts

acl = Kong::Acl.new({
consumer_id: 'a3dX2dh2-1adb-40a5-c042-63b19dbx83hF4',
group: 'group1'
group: 'group1',
tags: ["tag1", "tag2"]
})

acl.create
Expand Down
2 changes: 1 addition & 1 deletion lib/kong/acl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Kong
class Acl
include Base
include BelongsToConsumer
ATTRIBUTE_NAMES = %w(id group consumer_id).freeze
ATTRIBUTE_NAMES = %w(id group tags consumer_id).freeze
API_END_POINT = "/acls/".freeze
end
end
14 changes: 14 additions & 0 deletions lib/kong/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ def method_missing(method, *arguments, &block)
else
super
end
elsif method.to_s.start_with?('find_all_by_')
attribute = method.to_s.sub('find_all_by_', '')
if self.attribute_names.include?(attribute)
self.list({ attribute => arguments[0] })
else
super
end
else
super
end
Expand All @@ -50,6 +57,13 @@ def respond_to?(method, include_private = false)
else
super
end
elsif method.to_s.start_with?('find_all_by_')
attribute = method.to_s.sub('find_all_by_', '')
if self.attribute_names.include?(attribute)
return true
else
super
end
else
super
end
Expand Down
2 changes: 1 addition & 1 deletion spec/kong/acl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

describe Kong::Acl do
let(:valid_attribute_names) do
%w(id group consumer_id)
%w(id group tags consumer_id)
end

describe '::ATTRIBUTE_NAMES' do
Expand Down
8 changes: 8 additions & 0 deletions spec/kong/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,20 @@
it 'will respond to find_by_* methods' do
expect(Klass.respond_to?(:find_by_name)).to be_truthy
end

it 'will respond to find_all_by_* methods' do
expect(Klass.respond_to?(:find_all_by_name)).to be_truthy
end
end

context 'when attribute does not exit' do
it 'will not respond to find_by_* methods' do
expect(Klass.respond_to?(:find_by_invalid)).to be_falsey
end

it 'will not respond to find_all_by_* methods' do
expect(Klass.respond_to?(:find_all_by_invalid)).to be_falsey
end
end
end

Expand Down