{"action":"created","comment":{"url":"https://api.github.com/repos/rails/rails/pulls/comments/34536455","id":34536455,"diff_hunk":"@@ -0,0 +1,72 @@\n+require 'listen'\n+\n+module ActiveSupport\n+  class FileEventedUpdateChecker\n+    attr_reader :listener\n+    def initialize(files, directories={}, &block)\n+      @files = Set.new\n+      @files = files.map { |f| File.expand_path(f)}\n+      @dirs = Hash.new\n+      directories.each do |key,value|\n+        @dirs[File.expand_path(key)] = Array(value) if !Array(value).empty?\n+      end\n+      @block = block\n+      @modified = false\n+      watch_dirs = base_directories\n+      @listener = Listen.to(*watch_dirs,&method(:changed)) if !watch_dirs.empty?\n+      @listener.start if !@listener.nil?\n+    end\n+\n+    def updated?\n+      @modified\n+    end\n+\n+    def execute\n+      @block.call\n+    ensure\n+      @modified = false\n+    end\n+\n+    # Execute the block given if updated.\n+    def execute_if_updated\n+      if updated?\n+        execute\n+        true\n+      else\n+        false\n+      end\n+    end\n+\n+    def watching?(file)\n+      return true if @files.include?(file)\n+      cfile = file\n+      while !cfile.eql? \"/\"\n+        cfile = File.expand_path(\"#{cfile}/..\")\n+        if !@dirs[cfile].nil? and file.end_with?(*(@dirs[cfile].map {|ext| \".#{ext.to_s}\"}))\n+          return true\n+        end\n+      end\n+      # @dirs.map do |key,value|\n+      # \tif file.start_with?(key) and file.end_with?(*(value.map {|ext| \".#{ext.to_s}\"}))\n+      # \t\treturn true\n+      # \tend\n+      # end\n+      false\n+    end\n+\n+    def changed(modified, added, removed)\n+      return if @modified\n+      if (modified + added + removed).any? { |f| watching? f }\n+        @modified = true\n+      end\n+    end\n+\n+    def base_directories\n+      # TODO :- To add nearest parent directory which exists for watching when watching directory does not exist.\n+      values = (@files.map { |f| File.expand_path(\"#{f}/..\") if File.exist?(f) } + @dirs.keys.map {|dir| dir if File.directory?(dir)} if @dirs).uniq\n+      #(@files.map { |f| File.expand_path(\"#{f}/..\") if File.exists?(f) } + @dirs.keys.map {|dir| dir if File.directory?(dir)} if @dirs).uniq\n+      values = values.map {|v| v if !v.nil?}","path":"activesupport/lib/active_support/file_evented_update_checker.rb","position":68,"original_position":68,"commit_id":"c7391bd612a23490cd4b7b75fefb9a8af819d081","original_commit_id":"c7391bd612a23490cd4b7b75fefb9a8af819d081","user":{"login":"repinel","id":1685896,"avatar_url":"https://avatars.githubusercontent.com/u/1685896?v=3","gravatar_id":"","url":"https://api.github.com/users/repinel","html_url":"https://github.com/repinel","followers_url":"https://api.github.com/users/repinel/followers","following_url":"https://api.github.com/users/repinel/following{/other_user}","gists_url":"https://api.github.com/users/repinel/gists{/gist_id}","starred_url":"https://api.github.com/users/repinel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/repinel/subscriptions","organizations_url":"https://api.github.com/users/repinel/orgs","repos_url":"https://api.github.com/users/repinel/repos","events_url":"https://api.github.com/users/repinel/events{/privacy}","received_events_url":"https://api.github.com/users/repinel/received_events","type":"User","site_admin":false},"body":"This will just return a new array with the same elements' instances. Including `nil`. Are you trying to compact the array?","created_at":"2015-07-14T04:30:20Z","updated_at":"2015-07-14T04:30:20Z","html_url":"https://github.com/rails/rails/pull/20785#discussion_r34536455","pull_request_url":"https://api.github.com/repos/rails/rails/pulls/20785","_links":{"self":{"href":"https://api.github.com/repos/rails/rails/pulls/comments/34536455"},"html":{"href":"https://github.com/rails/rails/pull/20785#discussion_r34536455"},"pull_request":{"href":"https://api.github.com/repos/rails/rails/pulls/20785"}}},"pull_request":{"url":"https://api.github.com/repos/rails/rails/pulls/20785","id":39224742,"html_url":"https://github.com/rails/rails/pull/20785","diff_url":"https://github.com/rails/rails/pull/20785.diff","patch_url":"https://github.com/rails/rails/pull/20785.patch","issue_url":"https://api.github.com/repos/rails/rails/issues/20785","number":20785,"state":"open","locked":false,"title":"Evented File System Monitoring","user":{"login":"puneet24","id":5576707,"avatar_url":"https://avatars.githubusercontent.com/u/5576707?v=3","gravatar_id":"","url":"https://api.github.com/users/puneet24","html_url":"https://github.com/puneet24","followers_url":"https://api.github.com/users/puneet24/followers","following_url":"https://api.github.com/users/puneet24/following{/other_user}","gists_url":"https://api.github.com/users/puneet24/gists{/gist_id}","starred_url":"https://api.github.com/users/puneet24/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/puneet24/subscriptions","organizations_url":"https://api.github.com/users/puneet24/orgs","repos_url":"https://api.github.com/users/puneet24/repos","events_url":"https://api.github.com/users/puneet24/events{/privacy}","received_events_url":"https://api.github.com/users/puneet24/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-07-05T18:28:38Z","updated_at":"2015-07-14T04:30:20Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1d66b1ec742bcab38ae578d890b5c4685fadf80d","assignee":null,"milestone":{"url":"https://api.github.com/repos/rails/rails/milestones/34","html_url":"https://github.com/rails/rails/milestones/5.0.0","labels_url":"https://api.github.com/repos/rails/rails/milestones/34/labels","id":665192,"number":34,"title":"5.0.0","description":null,"creator":{"login":"rafaelfranca","id":47848,"avatar_url":"https://avatars.githubusercontent.com/u/47848?v=3","gravatar_id":"","url":"https://api.github.com/users/rafaelfranca","html_url":"https://github.com/rafaelfranca","followers_url":"https://api.github.com/users/rafaelfranca/followers","following_url":"https://api.github.com/users/rafaelfranca/following{/other_user}","gists_url":"https://api.github.com/users/rafaelfranca/gists{/gist_id}","starred_url":"https://api.github.com/users/rafaelfranca/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rafaelfranca/subscriptions","organizations_url":"https://api.github.com/users/rafaelfranca/orgs","repos_url":"https://api.github.com/users/rafaelfranca/repos","events_url":"https://api.github.com/users/rafaelfranca/events{/privacy}","received_events_url":"https://api.github.com/users/rafaelfranca/received_events","type":"User","site_admin":false},"open_issues":95,"closed_issues":120,"state":"open","created_at":"2014-05-21T00:58:22Z","updated_at":"2015-07-13T07:54:09Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/rails/rails/pulls/20785/commits","review_comments_url":"https://api.github.com/repos/rails/rails/pulls/20785/comments","review_comment_url":"https://api.github.com/repos/rails/rails/pulls/comments{/number}","comments_url":"https://api.github.com/repos/rails/rails/issues/20785/comments","statuses_url":"https://api.github.com/repos/rails/rails/statuses/c7391bd612a23490cd4b7b75fefb9a8af819d081","head":{"label":"puneet24:puneet","ref":"puneet","sha":"c7391bd612a23490cd4b7b75fefb9a8af819d081","user":{"login":"puneet24","id":5576707,"avatar_url":"https://avatars.githubusercontent.com/u/5576707?v=3","gravatar_id":"","url":"https://api.github.com/users/puneet24","html_url":"https://github.com/puneet24","followers_url":"https://api.github.com/users/puneet24/followers","following_url":"https://api.github.com/users/puneet24/following{/other_user}","gists_url":"https://api.github.com/users/puneet24/gists{/gist_id}","starred_url":"https://api.github.com/users/puneet24/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/puneet24/subscriptions","organizations_url":"https://api.github.com/users/puneet24/orgs","repos_url":"https://api.github.com/users/puneet24/repos","events_url":"https://api.github.com/users/puneet24/events{/privacy}","received_events_url":"https://api.github.com/users/puneet24/received_events","type":"User","site_admin":false},"repo":{"id":38483841,"name":"rails","full_name":"puneet24/rails","owner":{"login":"puneet24","id":5576707,"avatar_url":"https://avatars.githubusercontent.com/u/5576707?v=3","gravatar_id":"","url":"https://api.github.com/users/puneet24","html_url":"https://github.com/puneet24","followers_url":"https://api.github.com/users/puneet24/followers","following_url":"https://api.github.com/users/puneet24/following{/other_user}","gists_url":"https://api.github.com/users/puneet24/gists{/gist_id}","starred_url":"https://api.github.com/users/puneet24/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/puneet24/subscriptions","organizations_url":"https://api.github.com/users/puneet24/orgs","repos_url":"https://api.github.com/users/puneet24/repos","events_url":"https://api.github.com/users/puneet24/events{/privacy}","received_events_url":"https://api.github.com/users/puneet24/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/puneet24/rails","description":"Ruby on Rails","fork":true,"url":"https://api.github.com/repos/puneet24/rails","forks_url":"https://api.github.com/repos/puneet24/rails/forks","keys_url":"https://api.github.com/repos/puneet24/rails/keys{/key_id}","collaborators_url":"https://api.github.com/repos/puneet24/rails/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/puneet24/rails/teams","hooks_url":"https://api.github.com/repos/puneet24/rails/hooks","issue_events_url":"https://api.github.com/repos/puneet24/rails/issues/events{/number}","events_url":"https://api.github.com/repos/puneet24/rails/events","assignees_url":"https://api.github.com/repos/puneet24/rails/assignees{/user}","branches_url":"https://api.github.com/repos/puneet24/rails/branches{/branch}","tags_url":"https://api.github.com/repos/puneet24/rails/tags","blobs_url":"https://api.github.com/repos/puneet24/rails/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/puneet24/rails/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/puneet24/rails/git/refs{/sha}","trees_url":"https://api.github.com/repos/puneet24/rails/git/trees{/sha}","statuses_url":"https://api.github.com/repos/puneet24/rails/statuses/{sha}","languages_url":"https://api.github.com/repos/puneet24/rails/languages","stargazers_url":"https://api.github.com/repos/puneet24/rails/stargazers","contributors_url":"https://api.github.com/repos/puneet24/rails/contributors","subscribers_url":"https://api.github.com/repos/puneet24/rails/subscribers","subscription_url":"https://api.github.com/repos/puneet24/rails/subscription","commits_url":"https://api.github.com/repos/puneet24/rails/commits{/sha}","git_commits_url":"https://api.github.com/repos/puneet24/rails/git/commits{/sha}","comments_url":"https://api.github.com/repos/puneet24/rails/comments{/number}","issue_comment_url":"https://api.github.com/repos/puneet24/rails/issues/comments{/number}","contents_url":"https://api.github.com/repos/puneet24/rails/contents/{+path}","compare_url":"https://api.github.com/repos/puneet24/rails/compare/{base}...{head}","merges_url":"https://api.github.com/repos/puneet24/rails/merges","archive_url":"https://api.github.com/repos/puneet24/rails/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/puneet24/rails/downloads","issues_url":"https://api.github.com/repos/puneet24/rails/issues{/number}","pulls_url":"https://api.github.com/repos/puneet24/rails/pulls{/number}","milestones_url":"https://api.github.com/repos/puneet24/rails/milestones{/number}","notifications_url":"https://api.github.com/repos/puneet24/rails/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/puneet24/rails/labels{/name}","releases_url":"https://api.github.com/repos/puneet24/rails/releases{/id}","created_at":"2015-07-03T09:12:20Z","updated_at":"2015-07-03T09:12:48Z","pushed_at":"2015-07-12T07:03:44Z","git_url":"git://github.com/puneet24/rails.git","ssh_url":"git@github.com:puneet24/rails.git","clone_url":"https://github.com/puneet24/rails.git","svn_url":"https://github.com/puneet24/rails","homepage":"http://rubyonrails.org","size":144868,"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":"rails:master","ref":"master","sha":"794252d70990162d14da17ee854ad353e74297ee","user":{"login":"rails","id":4223,"avatar_url":"https://avatars.githubusercontent.com/u/4223?v=3","gravatar_id":"","url":"https://api.github.com/users/rails","html_url":"https://github.com/rails","followers_url":"https://api.github.com/users/rails/followers","following_url":"https://api.github.com/users/rails/following{/other_user}","gists_url":"https://api.github.com/users/rails/gists{/gist_id}","starred_url":"https://api.github.com/users/rails/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rails/subscriptions","organizations_url":"https://api.github.com/users/rails/orgs","repos_url":"https://api.github.com/users/rails/repos","events_url":"https://api.github.com/users/rails/events{/privacy}","received_events_url":"https://api.github.com/users/rails/received_events","type":"Organization","site_admin":false},"repo":{"id":8514,"name":"rails","full_name":"rails/rails","owner":{"login":"rails","id":4223,"avatar_url":"https://avatars.githubusercontent.com/u/4223?v=3","gravatar_id":"","url":"https://api.github.com/users/rails","html_url":"https://github.com/rails","followers_url":"https://api.github.com/users/rails/followers","following_url":"https://api.github.com/users/rails/following{/other_user}","gists_url":"https://api.github.com/users/rails/gists{/gist_id}","starred_url":"https://api.github.com/users/rails/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rails/subscriptions","organizations_url":"https://api.github.com/users/rails/orgs","repos_url":"https://api.github.com/users/rails/repos","events_url":"https://api.github.com/users/rails/events{/privacy}","received_events_url":"https://api.github.com/users/rails/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/rails/rails","description":"Ruby on Rails","fork":false,"url":"https://api.github.com/repos/rails/rails","forks_url":"https://api.github.com/repos/rails/rails/forks","keys_url":"https://api.github.com/repos/rails/rails/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rails/rails/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rails/rails/teams","hooks_url":"https://api.github.com/repos/rails/rails/hooks","issue_events_url":"https://api.github.com/repos/rails/rails/issues/events{/number}","events_url":"https://api.github.com/repos/rails/rails/events","assignees_url":"https://api.github.com/repos/rails/rails/assignees{/user}","branches_url":"https://api.github.com/repos/rails/rails/branches{/branch}","tags_url":"https://api.github.com/repos/rails/rails/tags","blobs_url":"https://api.github.com/repos/rails/rails/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rails/rails/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rails/rails/git/refs{/sha}","trees_url":"https://api.github.com/repos/rails/rails/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rails/rails/statuses/{sha}","languages_url":"https://api.github.com/repos/rails/rails/languages","stargazers_url":"https://api.github.com/repos/rails/rails/stargazers","contributors_url":"https://api.github.com/repos/rails/rails/contributors","subscribers_url":"https://api.github.com/repos/rails/rails/subscribers","subscription_url":"https://api.github.com/repos/rails/rails/subscription","commits_url":"https://api.github.com/repos/rails/rails/commits{/sha}","git_commits_url":"https://api.github.com/repos/rails/rails/git/commits{/sha}","comments_url":"https://api.github.com/repos/rails/rails/comments{/number}","issue_comment_url":"https://api.github.com/repos/rails/rails/issues/comments{/number}","contents_url":"https://api.github.com/repos/rails/rails/contents/{+path}","compare_url":"https://api.github.com/repos/rails/rails/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rails/rails/merges","archive_url":"https://api.github.com/repos/rails/rails/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rails/rails/downloads","issues_url":"https://api.github.com/repos/rails/rails/issues{/number}","pulls_url":"https://api.github.com/repos/rails/rails/pulls{/number}","milestones_url":"https://api.github.com/repos/rails/rails/milestones{/number}","notifications_url":"https://api.github.com/repos/rails/rails/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rails/rails/labels{/name}","releases_url":"https://api.github.com/repos/rails/rails/releases{/id}","created_at":"2008-04-11T02:19:47Z","updated_at":"2015-07-14T04:29:34Z","pushed_at":"2015-07-14T01:10:42Z","git_url":"git://github.com/rails/rails.git","ssh_url":"git@github.com:rails/rails.git","clone_url":"https://github.com/rails/rails.git","svn_url":"https://github.com/rails/rails","homepage":"http://rubyonrails.org","size":431355,"stargazers_count":26888,"watchers_count":26888,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":10740,"mirror_url":null,"open_issues_count":854,"forks":10740,"open_issues":854,"watchers":26888,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/rails/rails/pulls/20785"},"html":{"href":"https://github.com/rails/rails/pull/20785"},"issue":{"href":"https://api.github.com/repos/rails/rails/issues/20785"},"comments":{"href":"https://api.github.com/repos/rails/rails/issues/20785/comments"},"review_comments":{"href":"https://api.github.com/repos/rails/rails/pulls/20785/comments"},"review_comment":{"href":"https://api.github.com/repos/rails/rails/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/rails/rails/pulls/20785/commits"},"statuses":{"href":"https://api.github.com/repos/rails/rails/statuses/c7391bd612a23490cd4b7b75fefb9a8af819d081"}}}}