diff --git a/README.md b/README.md index f4eaea5..d612051 100644 --- a/README.md +++ b/README.md @@ -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' }) @@ -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 diff --git a/lib/kong/acl.rb b/lib/kong/acl.rb index ccee4bb..93c140a 100644 --- a/lib/kong/acl.rb +++ b/lib/kong/acl.rb @@ -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 diff --git a/lib/kong/base.rb b/lib/kong/base.rb index 0a5e7bd..3f90fce 100644 --- a/lib/kong/base.rb +++ b/lib/kong/base.rb @@ -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 @@ -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 diff --git a/spec/kong/acl_spec.rb b/spec/kong/acl_spec.rb index cb21c45..32dd40c 100644 --- a/spec/kong/acl_spec.rb +++ b/spec/kong/acl_spec.rb @@ -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 diff --git a/spec/kong/base_spec.rb b/spec/kong/base_spec.rb index 5e72f02..15792c5 100644 --- a/spec/kong/base_spec.rb +++ b/spec/kong/base_spec.rb @@ -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