{"action":"created","comment":{"url":"https://api.github.com/repos/ManageIQ/manageiq/pulls/comments/71026996","id":71026996,"diff_hunk":"@@ -3,23 +3,57 @@ class Settings\n     class DatabaseSource\n       include Vmdb::Logging\n \n-      attr_reader :resource\n+      attr_reader :resource_instance, :settings_holder_class\n \n-      def initialize(resource)\n-        @resource = resource\n+      # NOTE: resource - instance of MiqRegion, Zone or MiqServer\n+      #       klass    - class name of object which provides access to SettingsChange for resource\n+      #                  possible values of klass are in SETTINGS_HIERARCHY\n+      # EXAMPLE: 1. resource is instance of MiqServer and klass is 'Zone',\n+      #             than settings will be loaded from resource.zone.settings_changes\n+      #          2. resource is instance of MiqServer and klass is 'MiqRegion'\n+      #             than settings will be loaded from resource.miq_region.settings_changes\n+      \n+      def initialize(resource, klass)\n+        @resource_instance = resource\n+        @settings_holder_class = klass\n       end\n \n-      def load\n-        return if resource.nil?\n+      def self.sources_for(resource)\n+        return [] if resource.nil?\n+        hierarchy_index = SETTINGS_HIERARCHY.index(resource.class.name.to_sym)\n+        SETTINGS_HIERARCHY[0..hierarchy_index].collect do |klass|\n+          new(resource, klass)\n+        end\n+      end\n+\n+      def self.parent_sources_for(resource)\n+        sources_for(resource)[0...-1]\n+      end\n \n-        resource.settings_changes.reload.each_with_object({}) do |c, h|\n-          h.store_path(c.key_path, c.value)\n+      def load\n+        settings_holder_ = settings_holder\n+        if settings_holder_\n+          settings_holder_.settings_changes.reload.each_with_object({}) do |c, h|\n+            h.store_path(c.key_path, c.value)\n+          end\n         end\n       rescue => err\n         _log.error(\"#{err.class}: #{err}\")\n         _log.error(err.backtrace.join(\"\\n\"))\n         raise\n       end\n+\n+      private\n+\n+      METHODS_FOR_SETTINGS = %i(miq_region zone miq_server).freeze\n+      SETTINGS_HIERARCHY = %i(MiqRegion Zone MiqServer).freeze\n+\n+      def settings_holder\n+        return nill if resource_instance.nil?","path":"lib/vmdb/settings/database_source.rb","position":57,"original_position":57,"commit_id":"d65894e32d98a5ebce5ec55018a02ab0f7a04ed5","original_commit_id":"d65894e32d98a5ebce5ec55018a02ab0f7a04ed5","user":{"login":"Fryguy","id":52120,"avatar_url":"https://avatars.githubusercontent.com/u/52120?v=3","gravatar_id":"","url":"https://api.github.com/users/Fryguy","html_url":"https://github.com/Fryguy","followers_url":"https://api.github.com/users/Fryguy/followers","following_url":"https://api.github.com/users/Fryguy/following{/other_user}","gists_url":"https://api.github.com/users/Fryguy/gists{/gist_id}","starred_url":"https://api.github.com/users/Fryguy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Fryguy/subscriptions","organizations_url":"https://api.github.com/users/Fryguy/orgs","repos_url":"https://api.github.com/users/Fryguy/repos","events_url":"https://api.github.com/users/Fryguy/events{/privacy}","received_events_url":"https://api.github.com/users/Fryguy/received_events","type":"User","site_admin":false},"body":"Surprised if spec did not pick this up.","created_at":"2016-07-15T19:16:40Z","updated_at":"2016-07-15T19:16:40Z","html_url":"https://github.com/ManageIQ/manageiq/pull/9587#discussion_r71026996","pull_request_url":"https://api.github.com/repos/ManageIQ/manageiq/pulls/9587","_links":{"self":{"href":"https://api.github.com/repos/ManageIQ/manageiq/pulls/comments/71026996"},"html":{"href":"https://github.com/ManageIQ/manageiq/pull/9587#discussion_r71026996"},"pull_request":{"href":"https://api.github.com/repos/ManageIQ/manageiq/pulls/9587"}}},"pull_request":{"url":"https://api.github.com/repos/ManageIQ/manageiq/pulls/9587","id":76044893,"html_url":"https://github.com/ManageIQ/manageiq/pull/9587","diff_url":"https://github.com/ManageIQ/manageiq/pull/9587.diff","patch_url":"https://github.com/ManageIQ/manageiq/pull/9587.patch","issue_url":"https://api.github.com/repos/ManageIQ/manageiq/issues/9587","number":9587,"state":"open","locked":false,"title":"Settings on Region and Zone level – accepting from ‘settings_changes’ table","user":{"login":"yrudman","id":6556758,"avatar_url":"https://avatars.githubusercontent.com/u/6556758?v=3","gravatar_id":"","url":"https://api.github.com/users/yrudman","html_url":"https://github.com/yrudman","followers_url":"https://api.github.com/users/yrudman/followers","following_url":"https://api.github.com/users/yrudman/following{/other_user}","gists_url":"https://api.github.com/users/yrudman/gists{/gist_id}","starred_url":"https://api.github.com/users/yrudman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yrudman/subscriptions","organizations_url":"https://api.github.com/users/yrudman/orgs","repos_url":"https://api.github.com/users/yrudman/repos","events_url":"https://api.github.com/users/yrudman/events{/privacy}","received_events_url":"https://api.github.com/users/yrudman/received_events","type":"User","site_admin":false},"body":"Settings on Region and Zone level – accepting from ‘settings_changes’ table\r\n\r\nIn this PR:\r\n1.  Added ```:settings_changes``` association to ```Zone``` and ```MiqRegion``` classes\r\n2. Refactored ```Vmdb::Settings``` to support saving and loading settings for Region and Zone\r\n3. added ```resource``` parameter to ```Config.save_file()``` and ```Config#save()``` methods \r\n4. rspec for saving and loading settings on different levels\r\n5. modified config_spec.rb: ```save``` and ```save_file``` now passing instance of MiqServer as parameter.\r\n","created_at":"2016-07-01T22:39:02Z","updated_at":"2016-07-15T19:16:40Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9789085c5aa9a1c2cca9fded2cd2d1aaac83fcc1","assignee":{"login":"Fryguy","id":52120,"avatar_url":"https://avatars.githubusercontent.com/u/52120?v=3","gravatar_id":"","url":"https://api.github.com/users/Fryguy","html_url":"https://github.com/Fryguy","followers_url":"https://api.github.com/users/Fryguy/followers","following_url":"https://api.github.com/users/Fryguy/following{/other_user}","gists_url":"https://api.github.com/users/Fryguy/gists{/gist_id}","starred_url":"https://api.github.com/users/Fryguy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Fryguy/subscriptions","organizations_url":"https://api.github.com/users/Fryguy/orgs","repos_url":"https://api.github.com/users/Fryguy/repos","events_url":"https://api.github.com/users/Fryguy/events{/privacy}","received_events_url":"https://api.github.com/users/Fryguy/received_events","type":"User","site_admin":false},"assignees":[{"login":"Fryguy","id":52120,"avatar_url":"https://avatars.githubusercontent.com/u/52120?v=3","gravatar_id":"","url":"https://api.github.com/users/Fryguy","html_url":"https://github.com/Fryguy","followers_url":"https://api.github.com/users/Fryguy/followers","following_url":"https://api.github.com/users/Fryguy/following{/other_user}","gists_url":"https://api.github.com/users/Fryguy/gists{/gist_id}","starred_url":"https://api.github.com/users/Fryguy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Fryguy/subscriptions","organizations_url":"https://api.github.com/users/Fryguy/orgs","repos_url":"https://api.github.com/users/Fryguy/repos","events_url":"https://api.github.com/users/Fryguy/events{/privacy}","received_events_url":"https://api.github.com/users/Fryguy/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/ManageIQ/manageiq/pulls/9587/commits","review_comments_url":"https://api.github.com/repos/ManageIQ/manageiq/pulls/9587/comments","review_comment_url":"https://api.github.com/repos/ManageIQ/manageiq/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ManageIQ/manageiq/issues/9587/comments","statuses_url":"https://api.github.com/repos/ManageIQ/manageiq/statuses/d65894e32d98a5ebce5ec55018a02ab0f7a04ed5","head":{"label":"yrudman:settings-accepts-change_settings-from-zone-and-region-level","ref":"settings-accepts-change_settings-from-zone-and-region-level","sha":"d65894e32d98a5ebce5ec55018a02ab0f7a04ed5","user":{"login":"yrudman","id":6556758,"avatar_url":"https://avatars.githubusercontent.com/u/6556758?v=3","gravatar_id":"","url":"https://api.github.com/users/yrudman","html_url":"https://github.com/yrudman","followers_url":"https://api.github.com/users/yrudman/followers","following_url":"https://api.github.com/users/yrudman/following{/other_user}","gists_url":"https://api.github.com/users/yrudman/gists{/gist_id}","starred_url":"https://api.github.com/users/yrudman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yrudman/subscriptions","organizations_url":"https://api.github.com/users/yrudman/orgs","repos_url":"https://api.github.com/users/yrudman/repos","events_url":"https://api.github.com/users/yrudman/events{/privacy}","received_events_url":"https://api.github.com/users/yrudman/received_events","type":"User","site_admin":false},"repo":{"id":50465345,"name":"manageiq","full_name":"yrudman/manageiq","owner":{"login":"yrudman","id":6556758,"avatar_url":"https://avatars.githubusercontent.com/u/6556758?v=3","gravatar_id":"","url":"https://api.github.com/users/yrudman","html_url":"https://github.com/yrudman","followers_url":"https://api.github.com/users/yrudman/followers","following_url":"https://api.github.com/users/yrudman/following{/other_user}","gists_url":"https://api.github.com/users/yrudman/gists{/gist_id}","starred_url":"https://api.github.com/users/yrudman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yrudman/subscriptions","organizations_url":"https://api.github.com/users/yrudman/orgs","repos_url":"https://api.github.com/users/yrudman/repos","events_url":"https://api.github.com/users/yrudman/events{/privacy}","received_events_url":"https://api.github.com/users/yrudman/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/yrudman/manageiq","description":"ManageIQ Cloud Management Platform","fork":true,"url":"https://api.github.com/repos/yrudman/manageiq","forks_url":"https://api.github.com/repos/yrudman/manageiq/forks","keys_url":"https://api.github.com/repos/yrudman/manageiq/keys{/key_id}","collaborators_url":"https://api.github.com/repos/yrudman/manageiq/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/yrudman/manageiq/teams","hooks_url":"https://api.github.com/repos/yrudman/manageiq/hooks","issue_events_url":"https://api.github.com/repos/yrudman/manageiq/issues/events{/number}","events_url":"https://api.github.com/repos/yrudman/manageiq/events","assignees_url":"https://api.github.com/repos/yrudman/manageiq/assignees{/user}","branches_url":"https://api.github.com/repos/yrudman/manageiq/branches{/branch}","tags_url":"https://api.github.com/repos/yrudman/manageiq/tags","blobs_url":"https://api.github.com/repos/yrudman/manageiq/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/yrudman/manageiq/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/yrudman/manageiq/git/refs{/sha}","trees_url":"https://api.github.com/repos/yrudman/manageiq/git/trees{/sha}","statuses_url":"https://api.github.com/repos/yrudman/manageiq/statuses/{sha}","languages_url":"https://api.github.com/repos/yrudman/manageiq/languages","stargazers_url":"https://api.github.com/repos/yrudman/manageiq/stargazers","contributors_url":"https://api.github.com/repos/yrudman/manageiq/contributors","subscribers_url":"https://api.github.com/repos/yrudman/manageiq/subscribers","subscription_url":"https://api.github.com/repos/yrudman/manageiq/subscription","commits_url":"https://api.github.com/repos/yrudman/manageiq/commits{/sha}","git_commits_url":"https://api.github.com/repos/yrudman/manageiq/git/commits{/sha}","comments_url":"https://api.github.com/repos/yrudman/manageiq/comments{/number}","issue_comment_url":"https://api.github.com/repos/yrudman/manageiq/issues/comments{/number}","contents_url":"https://api.github.com/repos/yrudman/manageiq/contents/{+path}","compare_url":"https://api.github.com/repos/yrudman/manageiq/compare/{base}...{head}","merges_url":"https://api.github.com/repos/yrudman/manageiq/merges","archive_url":"https://api.github.com/repos/yrudman/manageiq/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/yrudman/manageiq/downloads","issues_url":"https://api.github.com/repos/yrudman/manageiq/issues{/number}","pulls_url":"https://api.github.com/repos/yrudman/manageiq/pulls{/number}","milestones_url":"https://api.github.com/repos/yrudman/manageiq/milestones{/number}","notifications_url":"https://api.github.com/repos/yrudman/manageiq/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/yrudman/manageiq/labels{/name}","releases_url":"https://api.github.com/repos/yrudman/manageiq/releases{/id}","deployments_url":"https://api.github.com/repos/yrudman/manageiq/deployments","created_at":"2016-01-26T22:55:59Z","updated_at":"2016-01-26T22:56:16Z","pushed_at":"2016-07-15T19:08:44Z","git_url":"git://github.com/yrudman/manageiq.git","ssh_url":"git@github.com:yrudman/manageiq.git","clone_url":"https://github.com/yrudman/manageiq.git","svn_url":"https://github.com/yrudman/manageiq","homepage":"manageiq.org","size":133934,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"ManageIQ:master","ref":"master","sha":"93203e099849c49d758ca33a4c228b411bb257e3","user":{"login":"ManageIQ","id":1125575,"avatar_url":"https://avatars.githubusercontent.com/u/1125575?v=3","gravatar_id":"","url":"https://api.github.com/users/ManageIQ","html_url":"https://github.com/ManageIQ","followers_url":"https://api.github.com/users/ManageIQ/followers","following_url":"https://api.github.com/users/ManageIQ/following{/other_user}","gists_url":"https://api.github.com/users/ManageIQ/gists{/gist_id}","starred_url":"https://api.github.com/users/ManageIQ/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ManageIQ/subscriptions","organizations_url":"https://api.github.com/users/ManageIQ/orgs","repos_url":"https://api.github.com/users/ManageIQ/repos","events_url":"https://api.github.com/users/ManageIQ/events{/privacy}","received_events_url":"https://api.github.com/users/ManageIQ/received_events","type":"Organization","site_admin":false},"repo":{"id":20789757,"name":"manageiq","full_name":"ManageIQ/manageiq","owner":{"login":"ManageIQ","id":1125575,"avatar_url":"https://avatars.githubusercontent.com/u/1125575?v=3","gravatar_id":"","url":"https://api.github.com/users/ManageIQ","html_url":"https://github.com/ManageIQ","followers_url":"https://api.github.com/users/ManageIQ/followers","following_url":"https://api.github.com/users/ManageIQ/following{/other_user}","gists_url":"https://api.github.com/users/ManageIQ/gists{/gist_id}","starred_url":"https://api.github.com/users/ManageIQ/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ManageIQ/subscriptions","organizations_url":"https://api.github.com/users/ManageIQ/orgs","repos_url":"https://api.github.com/users/ManageIQ/repos","events_url":"https://api.github.com/users/ManageIQ/events{/privacy}","received_events_url":"https://api.github.com/users/ManageIQ/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ManageIQ/manageiq","description":"ManageIQ Open-Source Management Platform","fork":false,"url":"https://api.github.com/repos/ManageIQ/manageiq","forks_url":"https://api.github.com/repos/ManageIQ/manageiq/forks","keys_url":"https://api.github.com/repos/ManageIQ/manageiq/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ManageIQ/manageiq/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ManageIQ/manageiq/teams","hooks_url":"https://api.github.com/repos/ManageIQ/manageiq/hooks","issue_events_url":"https://api.github.com/repos/ManageIQ/manageiq/issues/events{/number}","events_url":"https://api.github.com/repos/ManageIQ/manageiq/events","assignees_url":"https://api.github.com/repos/ManageIQ/manageiq/assignees{/user}","branches_url":"https://api.github.com/repos/ManageIQ/manageiq/branches{/branch}","tags_url":"https://api.github.com/repos/ManageIQ/manageiq/tags","blobs_url":"https://api.github.com/repos/ManageIQ/manageiq/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ManageIQ/manageiq/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ManageIQ/manageiq/git/refs{/sha}","trees_url":"https://api.github.com/repos/ManageIQ/manageiq/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ManageIQ/manageiq/statuses/{sha}","languages_url":"https://api.github.com/repos/ManageIQ/manageiq/languages","stargazers_url":"https://api.github.com/repos/ManageIQ/manageiq/stargazers","contributors_url":"https://api.github.com/repos/ManageIQ/manageiq/contributors","subscribers_url":"https://api.github.com/repos/ManageIQ/manageiq/subscribers","subscription_url":"https://api.github.com/repos/ManageIQ/manageiq/subscription","commits_url":"https://api.github.com/repos/ManageIQ/manageiq/commits{/sha}","git_commits_url":"https://api.github.com/repos/ManageIQ/manageiq/git/commits{/sha}","comments_url":"https://api.github.com/repos/ManageIQ/manageiq/comments{/number}","issue_comment_url":"https://api.github.com/repos/ManageIQ/manageiq/issues/comments{/number}","contents_url":"https://api.github.com/repos/ManageIQ/manageiq/contents/{+path}","compare_url":"https://api.github.com/repos/ManageIQ/manageiq/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ManageIQ/manageiq/merges","archive_url":"https://api.github.com/repos/ManageIQ/manageiq/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ManageIQ/manageiq/downloads","issues_url":"https://api.github.com/repos/ManageIQ/manageiq/issues{/number}","pulls_url":"https://api.github.com/repos/ManageIQ/manageiq/pulls{/number}","milestones_url":"https://api.github.com/repos/ManageIQ/manageiq/milestones{/number}","notifications_url":"https://api.github.com/repos/ManageIQ/manageiq/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ManageIQ/manageiq/labels{/name}","releases_url":"https://api.github.com/repos/ManageIQ/manageiq/releases{/id}","deployments_url":"https://api.github.com/repos/ManageIQ/manageiq/deployments","created_at":"2014-06-13T02:31:26Z","updated_at":"2016-07-13T16:26:10Z","pushed_at":"2016-07-15T19:08:45Z","git_url":"git://github.com/ManageIQ/manageiq.git","ssh_url":"git@github.com:ManageIQ/manageiq.git","clone_url":"https://github.com/ManageIQ/manageiq.git","svn_url":"https://github.com/ManageIQ/manageiq","homepage":"manageiq.org","size":177402,"stargazers_count":299,"watchers_count":299,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":323,"mirror_url":null,"open_issues_count":736,"forks":323,"open_issues":736,"watchers":299,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ManageIQ/manageiq/pulls/9587"},"html":{"href":"https://github.com/ManageIQ/manageiq/pull/9587"},"issue":{"href":"https://api.github.com/repos/ManageIQ/manageiq/issues/9587"},"comments":{"href":"https://api.github.com/repos/ManageIQ/manageiq/issues/9587/comments"},"review_comments":{"href":"https://api.github.com/repos/ManageIQ/manageiq/pulls/9587/comments"},"review_comment":{"href":"https://api.github.com/repos/ManageIQ/manageiq/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ManageIQ/manageiq/pulls/9587/commits"},"statuses":{"href":"https://api.github.com/repos/ManageIQ/manageiq/statuses/d65894e32d98a5ebce5ec55018a02ab0f7a04ed5"}}}}
{"actor":{"display_login":"Fryguy"}}