{"action":"created","comment":{"url":"https://api.github.com/repos/arista-eosplus/rbeapi/pulls/comments/43522171","id":43522171,"diff_hunk":"@@ -43,63 +43,439 @@ module Api\n     # the basis of such criteria as route metrics, access control lists, next\n     # hop addresses, and route tags.\n     #\n-    # rubocop:disable Metrics/MethodLength\n-    #\n     class Routemaps < Entity\n+      ##\n+      # get returns the routemap configuration\n+      #\n+      # @example\n+      #   {\n+      #     action: <string>,\n+      #     seqno: <integer>,\n+      #     match_rules: <array>,\n+      #     set_rules: <array>,\n+      #     continue: <integer>\n+      #     description: <string>\n+      #   }\n+      #\n+      # @param [String] name The routemap name to return a resource for from the\n+      #   nodes configuration\n+      #\n+      # @return [nil, Hash<Symbol, Object>] Returns the routemap resource as a\n+      #   Hash. If the specified name is not found in the nodes current\n+      #   configuration a nil object is returned\n       def get(name)\n-        entries = config.scan(/^route-map\\s#{name}\\s.+$/)\n+        entries = entries_regex(name)\n+        return nil unless entries\n+        parse_entries(entries)\n+      end\n \n-        entries.each_with_object([]) do |rm, arry|\n+      ##\n+      # getall returns a collection of routemap resource hashes from the nodes\n+      # running configuration. The routemap resource collection hash is keyed\n+      # by the unique routemap name.\n+      #\n+      # @example\n+      #   [\n+      #     <test:10>: {\n+      #       action: <string>,\n+      #       seqno: <integer>,\n+      #       match_rules: <array>,\n+      #       set_rules: <array>,\n+      #       continue: <integer>\n+      #       description: <string>\n+      #     },\n+      #     ...\n+      #   ]\n+      #\n+      # @return [Hash<Symbol, Object>] returns a hash that represents the\n+      #   entire routemap collection from the nodes running configuration.  If\n+      #   there are no routemap names configured, this method will return an\n+      #   empty hash.\n+      def getall\n+        routemaps = config.scan(/(?<=^route-map\\s)[^\\s]+/)\n+        return nil unless routemaps\n+        response = {}\n+        routemaps.each do |name|\n+          entries = entries_regex(name)\n+          response[name] = parse_entries(entries)\n+        end\n+        response\n+      end\n+\n+      ##\n+      # entries regex scans the config for the specified route-name. The method\n+      #   reduces duplication.\n+      #\n+      def entries_regex(name)\n+        config.scan(/^route-map\\s#{name}\\s.+$/)\n+      end\n+      private :entries_regex\n+\n+      ##\n+      # parse entries is a private method to get the routemap rules.\n+      #\n+      # @return [Hash<Symbol, Object>] returns a hash that represents the\n+      #   rules for routemaps from the nodes running configuration.  If\n+      #   there are no routemaps configured, this method will return an empty\n+      #    hash.\n+      #\n+      def parse_entries(entries)\n+        entries.each_with_object([]) do |rm|\n           mdata = /route-map\\s(.+)\\s(.+)\\s(\\d+)$/.match(rm)\n           rules = get_block(rm)\n-          rule_hsh = { 'action' => mdata[2], 'seqno' => mdata[3],\n-                       'match_rules' => [], 'set_rules' => [],\n-                       'continue_rules' => [] }\n-\n-          parsed = rules.split(\"\\n\").each_with_object({}) do |rule, hsh|\n-            mdata = /\\s{3}(\\w+)\\s/.match(rule)\n-            case mdata.nil? ? nil : mdata[1]\n-            when 'match'\n-              hsh['match_rules'] = [] unless hsh.include?('match')\n-              hsh['match_rules'] << rule.strip\n-            when 'set'\n-              hsh['set_rules'] = [] unless hsh.include?('set')\n-              hsh['set_rules'] << rule.strip\n-            when 'continue'\n-              hsh['continue_rules'] = [] unless hsh.include?('continue')\n-              hsh['continue_rules'] << rule.strip\n+          rule_hsh = { action: mdata[2], seqno: mdata[3].to_i }\n+          unless rules.nil?\n+            rules.split(\"\\n\").each_with_object({}) do |rule|\n+              parse_rule(rule, rule_hsh)\n             end\n           end\n-          rule_hsh.update(parsed)\n-          arry << rule_hsh\n+          return rule_hsh","path":"lib/rbeapi/api/routemaps.rb","position":112,"original_position":112,"commit_id":"d7733fcac34abcc6ff50c50b73c181a5c139fc1e","original_commit_id":"d7733fcac34abcc6ff50c50b73c181a5c139fc1e","user":{"login":"websitescenes","id":2442771,"avatar_url":"https://avatars.githubusercontent.com/u/2442771?v=3","gravatar_id":"","url":"https://api.github.com/users/websitescenes","html_url":"https://github.com/websitescenes","followers_url":"https://api.github.com/users/websitescenes/followers","following_url":"https://api.github.com/users/websitescenes/following{/other_user}","gists_url":"https://api.github.com/users/websitescenes/gists{/gist_id}","starred_url":"https://api.github.com/users/websitescenes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/websitescenes/subscriptions","organizations_url":"https://api.github.com/users/websitescenes/orgs","repos_url":"https://api.github.com/users/websitescenes/repos","events_url":"https://api.github.com/users/websitescenes/events{/privacy}","received_events_url":"https://api.github.com/users/websitescenes/received_events","type":"User","site_admin":false},"body":"rule_hsh is only available in the loop. I can think about another way to write this if you don't like it.","created_at":"2015-10-30T16:27:13Z","updated_at":"2015-10-30T16:27:13Z","html_url":"https://github.com/arista-eosplus/rbeapi/pull/63#discussion_r43522171","pull_request_url":"https://api.github.com/repos/arista-eosplus/rbeapi/pulls/63","_links":{"self":{"href":"https://api.github.com/repos/arista-eosplus/rbeapi/pulls/comments/43522171"},"html":{"href":"https://github.com/arista-eosplus/rbeapi/pull/63#discussion_r43522171"},"pull_request":{"href":"https://api.github.com/repos/arista-eosplus/rbeapi/pulls/63"}}},"pull_request":{"url":"https://api.github.com/repos/arista-eosplus/rbeapi/pulls/63","id":49233956,"html_url":"https://github.com/arista-eosplus/rbeapi/pull/63","diff_url":"https://github.com/arista-eosplus/rbeapi/pull/63.diff","patch_url":"https://github.com/arista-eosplus/rbeapi/pull/63.patch","issue_url":"https://api.github.com/repos/arista-eosplus/rbeapi/issues/63","number":63,"state":"open","locked":false,"title":"Adding feature routemap","user":{"login":"websitescenes","id":2442771,"avatar_url":"https://avatars.githubusercontent.com/u/2442771?v=3","gravatar_id":"","url":"https://api.github.com/users/websitescenes","html_url":"https://github.com/websitescenes","followers_url":"https://api.github.com/users/websitescenes/followers","following_url":"https://api.github.com/users/websitescenes/following{/other_user}","gists_url":"https://api.github.com/users/websitescenes/gists{/gist_id}","starred_url":"https://api.github.com/users/websitescenes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/websitescenes/subscriptions","organizations_url":"https://api.github.com/users/websitescenes/orgs","repos_url":"https://api.github.com/users/websitescenes/repos","events_url":"https://api.github.com/users/websitescenes/events{/privacy}","received_events_url":"https://api.github.com/users/websitescenes/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-10-30T05:51:24Z","updated_at":"2015-10-30T16:27:13Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0250d43c0729a7e52ed915af0f7fb1026cebb27c","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/arista-eosplus/rbeapi/pulls/63/commits","review_comments_url":"https://api.github.com/repos/arista-eosplus/rbeapi/pulls/63/comments","review_comment_url":"https://api.github.com/repos/arista-eosplus/rbeapi/pulls/comments{/number}","comments_url":"https://api.github.com/repos/arista-eosplus/rbeapi/issues/63/comments","statuses_url":"https://api.github.com/repos/arista-eosplus/rbeapi/statuses/d7733fcac34abcc6ff50c50b73c181a5c139fc1e","head":{"label":"arista-eosplus:feature-routemap","ref":"feature-routemap","sha":"d7733fcac34abcc6ff50c50b73c181a5c139fc1e","user":{"login":"arista-eosplus","id":6643264,"avatar_url":"https://avatars.githubusercontent.com/u/6643264?v=3","gravatar_id":"","url":"https://api.github.com/users/arista-eosplus","html_url":"https://github.com/arista-eosplus","followers_url":"https://api.github.com/users/arista-eosplus/followers","following_url":"https://api.github.com/users/arista-eosplus/following{/other_user}","gists_url":"https://api.github.com/users/arista-eosplus/gists{/gist_id}","starred_url":"https://api.github.com/users/arista-eosplus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arista-eosplus/subscriptions","organizations_url":"https://api.github.com/users/arista-eosplus/orgs","repos_url":"https://api.github.com/users/arista-eosplus/repos","events_url":"https://api.github.com/users/arista-eosplus/events{/privacy}","received_events_url":"https://api.github.com/users/arista-eosplus/received_events","type":"Organization","site_admin":false},"repo":{"id":29896197,"name":"rbeapi","full_name":"arista-eosplus/rbeapi","owner":{"login":"arista-eosplus","id":6643264,"avatar_url":"https://avatars.githubusercontent.com/u/6643264?v=3","gravatar_id":"","url":"https://api.github.com/users/arista-eosplus","html_url":"https://github.com/arista-eosplus","followers_url":"https://api.github.com/users/arista-eosplus/followers","following_url":"https://api.github.com/users/arista-eosplus/following{/other_user}","gists_url":"https://api.github.com/users/arista-eosplus/gists{/gist_id}","starred_url":"https://api.github.com/users/arista-eosplus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arista-eosplus/subscriptions","organizations_url":"https://api.github.com/users/arista-eosplus/orgs","repos_url":"https://api.github.com/users/arista-eosplus/repos","events_url":"https://api.github.com/users/arista-eosplus/events{/privacy}","received_events_url":"https://api.github.com/users/arista-eosplus/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/arista-eosplus/rbeapi","description":"Ruby client for Arista eAPI","fork":false,"url":"https://api.github.com/repos/arista-eosplus/rbeapi","forks_url":"https://api.github.com/repos/arista-eosplus/rbeapi/forks","keys_url":"https://api.github.com/repos/arista-eosplus/rbeapi/keys{/key_id}","collaborators_url":"https://api.github.com/repos/arista-eosplus/rbeapi/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/arista-eosplus/rbeapi/teams","hooks_url":"https://api.github.com/repos/arista-eosplus/rbeapi/hooks","issue_events_url":"https://api.github.com/repos/arista-eosplus/rbeapi/issues/events{/number}","events_url":"https://api.github.com/repos/arista-eosplus/rbeapi/events","assignees_url":"https://api.github.com/repos/arista-eosplus/rbeapi/assignees{/user}","branches_url":"https://api.github.com/repos/arista-eosplus/rbeapi/branches{/branch}","tags_url":"https://api.github.com/repos/arista-eosplus/rbeapi/tags","blobs_url":"https://api.github.com/repos/arista-eosplus/rbeapi/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/arista-eosplus/rbeapi/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/arista-eosplus/rbeapi/git/refs{/sha}","trees_url":"https://api.github.com/repos/arista-eosplus/rbeapi/git/trees{/sha}","statuses_url":"https://api.github.com/repos/arista-eosplus/rbeapi/statuses/{sha}","languages_url":"https://api.github.com/repos/arista-eosplus/rbeapi/languages","stargazers_url":"https://api.github.com/repos/arista-eosplus/rbeapi/stargazers","contributors_url":"https://api.github.com/repos/arista-eosplus/rbeapi/contributors","subscribers_url":"https://api.github.com/repos/arista-eosplus/rbeapi/subscribers","subscription_url":"https://api.github.com/repos/arista-eosplus/rbeapi/subscription","commits_url":"https://api.github.com/repos/arista-eosplus/rbeapi/commits{/sha}","git_commits_url":"https://api.github.com/repos/arista-eosplus/rbeapi/git/commits{/sha}","comments_url":"https://api.github.com/repos/arista-eosplus/rbeapi/comments{/number}","issue_comment_url":"https://api.github.com/repos/arista-eosplus/rbeapi/issues/comments{/number}","contents_url":"https://api.github.com/repos/arista-eosplus/rbeapi/contents/{+path}","compare_url":"https://api.github.com/repos/arista-eosplus/rbeapi/compare/{base}...{head}","merges_url":"https://api.github.com/repos/arista-eosplus/rbeapi/merges","archive_url":"https://api.github.com/repos/arista-eosplus/rbeapi/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/arista-eosplus/rbeapi/downloads","issues_url":"https://api.github.com/repos/arista-eosplus/rbeapi/issues{/number}","pulls_url":"https://api.github.com/repos/arista-eosplus/rbeapi/pulls{/number}","milestones_url":"https://api.github.com/repos/arista-eosplus/rbeapi/milestones{/number}","notifications_url":"https://api.github.com/repos/arista-eosplus/rbeapi/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/arista-eosplus/rbeapi/labels{/name}","releases_url":"https://api.github.com/repos/arista-eosplus/rbeapi/releases{/id}","created_at":"2015-01-27T03:49:06Z","updated_at":"2015-09-08T21:03:21Z","pushed_at":"2015-10-30T16:10:57Z","git_url":"git://github.com/arista-eosplus/rbeapi.git","ssh_url":"git@github.com:arista-eosplus/rbeapi.git","clone_url":"https://github.com/arista-eosplus/rbeapi.git","svn_url":"https://github.com/arista-eosplus/rbeapi","homepage":null,"size":992,"stargazers_count":7,"watchers_count":7,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":6,"mirror_url":null,"open_issues_count":10,"forks":6,"open_issues":10,"watchers":7,"default_branch":"develop"}},"base":{"label":"arista-eosplus:develop","ref":"develop","sha":"18f219fed845e7419a97f31d22cabb0a0cb2b5d7","user":{"login":"arista-eosplus","id":6643264,"avatar_url":"https://avatars.githubusercontent.com/u/6643264?v=3","gravatar_id":"","url":"https://api.github.com/users/arista-eosplus","html_url":"https://github.com/arista-eosplus","followers_url":"https://api.github.com/users/arista-eosplus/followers","following_url":"https://api.github.com/users/arista-eosplus/following{/other_user}","gists_url":"https://api.github.com/users/arista-eosplus/gists{/gist_id}","starred_url":"https://api.github.com/users/arista-eosplus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arista-eosplus/subscriptions","organizations_url":"https://api.github.com/users/arista-eosplus/orgs","repos_url":"https://api.github.com/users/arista-eosplus/repos","events_url":"https://api.github.com/users/arista-eosplus/events{/privacy}","received_events_url":"https://api.github.com/users/arista-eosplus/received_events","type":"Organization","site_admin":false},"repo":{"id":29896197,"name":"rbeapi","full_name":"arista-eosplus/rbeapi","owner":{"login":"arista-eosplus","id":6643264,"avatar_url":"https://avatars.githubusercontent.com/u/6643264?v=3","gravatar_id":"","url":"https://api.github.com/users/arista-eosplus","html_url":"https://github.com/arista-eosplus","followers_url":"https://api.github.com/users/arista-eosplus/followers","following_url":"https://api.github.com/users/arista-eosplus/following{/other_user}","gists_url":"https://api.github.com/users/arista-eosplus/gists{/gist_id}","starred_url":"https://api.github.com/users/arista-eosplus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arista-eosplus/subscriptions","organizations_url":"https://api.github.com/users/arista-eosplus/orgs","repos_url":"https://api.github.com/users/arista-eosplus/repos","events_url":"https://api.github.com/users/arista-eosplus/events{/privacy}","received_events_url":"https://api.github.com/users/arista-eosplus/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/arista-eosplus/rbeapi","description":"Ruby client for Arista eAPI","fork":false,"url":"https://api.github.com/repos/arista-eosplus/rbeapi","forks_url":"https://api.github.com/repos/arista-eosplus/rbeapi/forks","keys_url":"https://api.github.com/repos/arista-eosplus/rbeapi/keys{/key_id}","collaborators_url":"https://api.github.com/repos/arista-eosplus/rbeapi/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/arista-eosplus/rbeapi/teams","hooks_url":"https://api.github.com/repos/arista-eosplus/rbeapi/hooks","issue_events_url":"https://api.github.com/repos/arista-eosplus/rbeapi/issues/events{/number}","events_url":"https://api.github.com/repos/arista-eosplus/rbeapi/events","assignees_url":"https://api.github.com/repos/arista-eosplus/rbeapi/assignees{/user}","branches_url":"https://api.github.com/repos/arista-eosplus/rbeapi/branches{/branch}","tags_url":"https://api.github.com/repos/arista-eosplus/rbeapi/tags","blobs_url":"https://api.github.com/repos/arista-eosplus/rbeapi/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/arista-eosplus/rbeapi/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/arista-eosplus/rbeapi/git/refs{/sha}","trees_url":"https://api.github.com/repos/arista-eosplus/rbeapi/git/trees{/sha}","statuses_url":"https://api.github.com/repos/arista-eosplus/rbeapi/statuses/{sha}","languages_url":"https://api.github.com/repos/arista-eosplus/rbeapi/languages","stargazers_url":"https://api.github.com/repos/arista-eosplus/rbeapi/stargazers","contributors_url":"https://api.github.com/repos/arista-eosplus/rbeapi/contributors","subscribers_url":"https://api.github.com/repos/arista-eosplus/rbeapi/subscribers","subscription_url":"https://api.github.com/repos/arista-eosplus/rbeapi/subscription","commits_url":"https://api.github.com/repos/arista-eosplus/rbeapi/commits{/sha}","git_commits_url":"https://api.github.com/repos/arista-eosplus/rbeapi/git/commits{/sha}","comments_url":"https://api.github.com/repos/arista-eosplus/rbeapi/comments{/number}","issue_comment_url":"https://api.github.com/repos/arista-eosplus/rbeapi/issues/comments{/number}","contents_url":"https://api.github.com/repos/arista-eosplus/rbeapi/contents/{+path}","compare_url":"https://api.github.com/repos/arista-eosplus/rbeapi/compare/{base}...{head}","merges_url":"https://api.github.com/repos/arista-eosplus/rbeapi/merges","archive_url":"https://api.github.com/repos/arista-eosplus/rbeapi/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/arista-eosplus/rbeapi/downloads","issues_url":"https://api.github.com/repos/arista-eosplus/rbeapi/issues{/number}","pulls_url":"https://api.github.com/repos/arista-eosplus/rbeapi/pulls{/number}","milestones_url":"https://api.github.com/repos/arista-eosplus/rbeapi/milestones{/number}","notifications_url":"https://api.github.com/repos/arista-eosplus/rbeapi/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/arista-eosplus/rbeapi/labels{/name}","releases_url":"https://api.github.com/repos/arista-eosplus/rbeapi/releases{/id}","created_at":"2015-01-27T03:49:06Z","updated_at":"2015-09-08T21:03:21Z","pushed_at":"2015-10-30T16:10:57Z","git_url":"git://github.com/arista-eosplus/rbeapi.git","ssh_url":"git@github.com:arista-eosplus/rbeapi.git","clone_url":"https://github.com/arista-eosplus/rbeapi.git","svn_url":"https://github.com/arista-eosplus/rbeapi","homepage":null,"size":992,"stargazers_count":7,"watchers_count":7,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":6,"mirror_url":null,"open_issues_count":10,"forks":6,"open_issues":10,"watchers":7,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/arista-eosplus/rbeapi/pulls/63"},"html":{"href":"https://github.com/arista-eosplus/rbeapi/pull/63"},"issue":{"href":"https://api.github.com/repos/arista-eosplus/rbeapi/issues/63"},"comments":{"href":"https://api.github.com/repos/arista-eosplus/rbeapi/issues/63/comments"},"review_comments":{"href":"https://api.github.com/repos/arista-eosplus/rbeapi/pulls/63/comments"},"review_comment":{"href":"https://api.github.com/repos/arista-eosplus/rbeapi/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/arista-eosplus/rbeapi/pulls/63/commits"},"statuses":{"href":"https://api.github.com/repos/arista-eosplus/rbeapi/statuses/d7733fcac34abcc6ff50c50b73c181a5c139fc1e"}}}}