{"action":"created","comment":{"url":"https://api.github.com/repos/TwP/logging/pulls/comments/27345860","id":27345860,"diff_hunk":"@@ -84,61 +84,48 @@ def initialize( name, opts = {} )\n \n       # grab our options\n       @size = opts.getopt(:size, :as => Integer)\n-\n-      code = 'def sufficiently_aged?() false end'\n+      @age = opts.getopt(:age)\n       @age_fn = @fn + '.age'\n       @age_fn_mtime = nil\n \n-      case @age = opts.getopt(:age)\n-      when 'daily'\n-        code = <<-CODE\n-        def sufficiently_aged?\n-          @age_fn_mtime ||= ::File.mtime(@age_fn)\n+      do_age_predicate_setup = lambda do\n+\n+        set_mtime = lambda { @age_fn_mtime ||= ::File.mtime(@age_fn) }\n+\n+        daily_predicate = lambda do\n           now = Time.now\n-          if (now.day != @age_fn_mtime.day) or (now - @age_fn_mtime) > 86400\n-            return true\n-          end\n-          false\n+          set_mtime.call\n+          (now.day != @age_fn_mtime.day) or (now - @age_fn_mtime) > 86400\n         end\n-        CODE\n-      when 'weekly'\n-        code = <<-CODE\n-        def sufficiently_aged?\n-          @age_fn_mtime ||= ::File.mtime(@age_fn)\n-          if (Time.now - @age_fn_mtime) > 604800\n-            return true\n-          end\n-          false\n+\n+        weekly_predicate = lambda do\n+          set_mtime.call\n+          (Time.now - @age_fn_mtime) > 604800\n         end\n-        CODE\n-      when 'monthly'\n-        code = <<-CODE\n-        def sufficiently_aged?\n-          @age_fn_mtime ||= ::File.mtime(@age_fn)\n+\n+        monthly_predicate = lambda do\n           now = Time.now\n-          if (now.month != @age_fn_mtime.month) or (now - @age_fn_mtime) > 2678400\n-            return true\n-          end\n-          false\n+          set_mtime.call\n+          (now.month != @age_fn_mtime.month) or (now - @age_fn_mtime) > 2678400\n         end\n-        CODE\n-      when Integer, String\n-        @age = Integer(@age)\n-        code = <<-CODE\n-        def sufficiently_aged?\n-          @age_fn_mtime ||= ::File.mtime(@age_fn)\n-          if (Time.now - @age_fn_mtime) > @age\n-            return true\n-          end\n-          false\n+\n+        seconds_predicate = lambda do\n+          set_mtime.call\n+          (Time.now - @age_fn_mtime) > @age\n+        end\n+\n+        @age_predicate = case @age\n+           when 'daily';         daily_predicate\n+           when 'weekly';        weekly_predicate\n+           when 'monthly';       monthly_predicate\n+           when Integer, String; @age = Integer(@age); seconds_predicate\n+           else lambda { false }\n         end\n-        CODE\n       end\n \n-      FileUtils.touch(@age_fn) if @age and !test(?f, @age_fn)\n+      do_age_predicate_setup.call","path":"lib/logging/appenders/rolling_file.rb","position":84,"original_position":84,"commit_id":"2c665d85367ef4b57f38232e4bb26634a7c17287","original_commit_id":"2c665d85367ef4b57f38232e4bb26634a7c17287","user":{"login":"TwP","id":6323,"avatar_url":"https://avatars.githubusercontent.com/u/6323?v=3","gravatar_id":"","url":"https://api.github.com/users/TwP","html_url":"https://github.com/TwP","followers_url":"https://api.github.com/users/TwP/followers","following_url":"https://api.github.com/users/TwP/following{/other_user}","gists_url":"https://api.github.com/users/TwP/gists{/gist_id}","starred_url":"https://api.github.com/users/TwP/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TwP/subscriptions","organizations_url":"https://api.github.com/users/TwP/orgs","repos_url":"https://api.github.com/users/TwP/repos","events_url":"https://api.github.com/users/TwP/events{/privacy}","received_events_url":"https://api.github.com/users/TwP/received_events","type":"User","site_admin":true},"body":"It seems a bit overkill here to define a lambda and then immediately `call` the lambda after it is defined. It would be more straightforward to define a `setup_age_checks` method and invoke that from the initializer.","created_at":"2015-03-28T15:39:31Z","updated_at":"2015-03-28T15:39:31Z","html_url":"https://github.com/TwP/logging/pull/80#discussion_r27345860","pull_request_url":"https://api.github.com/repos/TwP/logging/pulls/80","_links":{"self":{"href":"https://api.github.com/repos/TwP/logging/pulls/comments/27345860"},"html":{"href":"https://github.com/TwP/logging/pull/80#discussion_r27345860"},"pull_request":{"href":"https://api.github.com/repos/TwP/logging/pulls/80"}}},"pull_request":{"url":"https://api.github.com/repos/TwP/logging/pulls/80","id":12628394,"html_url":"https://github.com/TwP/logging/pull/80","diff_url":"https://github.com/TwP/logging/pull/80.diff","patch_url":"https://github.com/TwP/logging/pull/80.patch","issue_url":"https://api.github.com/repos/TwP/logging/issues/80","number":80,"state":"open","locked":false,"title":"Use lambdas instead of eval'ing code for setting up age tests.","user":{"login":"keithrbennett","id":28410,"avatar_url":"https://avatars.githubusercontent.com/u/28410?v=3","gravatar_id":"","url":"https://api.github.com/users/keithrbennett","html_url":"https://github.com/keithrbennett","followers_url":"https://api.github.com/users/keithrbennett/followers","following_url":"https://api.github.com/users/keithrbennett/following{/other_user}","gists_url":"https://api.github.com/users/keithrbennett/gists{/gist_id}","starred_url":"https://api.github.com/users/keithrbennett/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/keithrbennett/subscriptions","organizations_url":"https://api.github.com/users/keithrbennett/orgs","repos_url":"https://api.github.com/users/keithrbennett/repos","events_url":"https://api.github.com/users/keithrbennett/events{/privacy}","received_events_url":"https://api.github.com/users/keithrbennett/received_events","type":"User","site_admin":false},"body":"Somewhat simplifies the RollingAppender's initialization by using lambdas instead of eval'ing a code string for the various age test modes (daily, weekly. monthly, seconds).","created_at":"2014-02-17T21:31:40Z","updated_at":"2015-03-28T15:39:31Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d6bba61c635c09a1537ef499502d913b5f3945a5","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/TwP/logging/pulls/80/commits","review_comments_url":"https://api.github.com/repos/TwP/logging/pulls/80/comments","review_comment_url":"https://api.github.com/repos/TwP/logging/pulls/comments{/number}","comments_url":"https://api.github.com/repos/TwP/logging/issues/80/comments","statuses_url":"https://api.github.com/repos/TwP/logging/statuses/2c665d85367ef4b57f38232e4bb26634a7c17287","head":{"label":"keithrbennett:simplifies_age_test","ref":"simplifies_age_test","sha":"2c665d85367ef4b57f38232e4bb26634a7c17287","user":{"login":"keithrbennett","id":28410,"avatar_url":"https://avatars.githubusercontent.com/u/28410?v=3","gravatar_id":"","url":"https://api.github.com/users/keithrbennett","html_url":"https://github.com/keithrbennett","followers_url":"https://api.github.com/users/keithrbennett/followers","following_url":"https://api.github.com/users/keithrbennett/following{/other_user}","gists_url":"https://api.github.com/users/keithrbennett/gists{/gist_id}","starred_url":"https://api.github.com/users/keithrbennett/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/keithrbennett/subscriptions","organizations_url":"https://api.github.com/users/keithrbennett/orgs","repos_url":"https://api.github.com/users/keithrbennett/repos","events_url":"https://api.github.com/users/keithrbennett/events{/privacy}","received_events_url":"https://api.github.com/users/keithrbennett/received_events","type":"User","site_admin":false},"repo":{"id":16925980,"name":"logging","full_name":"keithrbennett/logging","owner":{"login":"keithrbennett","id":28410,"avatar_url":"https://avatars.githubusercontent.com/u/28410?v=3","gravatar_id":"","url":"https://api.github.com/users/keithrbennett","html_url":"https://github.com/keithrbennett","followers_url":"https://api.github.com/users/keithrbennett/followers","following_url":"https://api.github.com/users/keithrbennett/following{/other_user}","gists_url":"https://api.github.com/users/keithrbennett/gists{/gist_id}","starred_url":"https://api.github.com/users/keithrbennett/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/keithrbennett/subscriptions","organizations_url":"https://api.github.com/users/keithrbennett/orgs","repos_url":"https://api.github.com/users/keithrbennett/repos","events_url":"https://api.github.com/users/keithrbennett/events{/privacy}","received_events_url":"https://api.github.com/users/keithrbennett/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/keithrbennett/logging","description":"A flexible logging library for use in Ruby programs based on the design of Java's log4j library.","fork":true,"url":"https://api.github.com/repos/keithrbennett/logging","forks_url":"https://api.github.com/repos/keithrbennett/logging/forks","keys_url":"https://api.github.com/repos/keithrbennett/logging/keys{/key_id}","collaborators_url":"https://api.github.com/repos/keithrbennett/logging/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/keithrbennett/logging/teams","hooks_url":"https://api.github.com/repos/keithrbennett/logging/hooks","issue_events_url":"https://api.github.com/repos/keithrbennett/logging/issues/events{/number}","events_url":"https://api.github.com/repos/keithrbennett/logging/events","assignees_url":"https://api.github.com/repos/keithrbennett/logging/assignees{/user}","branches_url":"https://api.github.com/repos/keithrbennett/logging/branches{/branch}","tags_url":"https://api.github.com/repos/keithrbennett/logging/tags","blobs_url":"https://api.github.com/repos/keithrbennett/logging/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/keithrbennett/logging/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/keithrbennett/logging/git/refs{/sha}","trees_url":"https://api.github.com/repos/keithrbennett/logging/git/trees{/sha}","statuses_url":"https://api.github.com/repos/keithrbennett/logging/statuses/{sha}","languages_url":"https://api.github.com/repos/keithrbennett/logging/languages","stargazers_url":"https://api.github.com/repos/keithrbennett/logging/stargazers","contributors_url":"https://api.github.com/repos/keithrbennett/logging/contributors","subscribers_url":"https://api.github.com/repos/keithrbennett/logging/subscribers","subscription_url":"https://api.github.com/repos/keithrbennett/logging/subscription","commits_url":"https://api.github.com/repos/keithrbennett/logging/commits{/sha}","git_commits_url":"https://api.github.com/repos/keithrbennett/logging/git/commits{/sha}","comments_url":"https://api.github.com/repos/keithrbennett/logging/comments{/number}","issue_comment_url":"https://api.github.com/repos/keithrbennett/logging/issues/comments{/number}","contents_url":"https://api.github.com/repos/keithrbennett/logging/contents/{+path}","compare_url":"https://api.github.com/repos/keithrbennett/logging/compare/{base}...{head}","merges_url":"https://api.github.com/repos/keithrbennett/logging/merges","archive_url":"https://api.github.com/repos/keithrbennett/logging/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/keithrbennett/logging/downloads","issues_url":"https://api.github.com/repos/keithrbennett/logging/issues{/number}","pulls_url":"https://api.github.com/repos/keithrbennett/logging/pulls{/number}","milestones_url":"https://api.github.com/repos/keithrbennett/logging/milestones{/number}","notifications_url":"https://api.github.com/repos/keithrbennett/logging/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/keithrbennett/logging/labels{/name}","releases_url":"https://api.github.com/repos/keithrbennett/logging/releases{/id}","created_at":"2014-02-17T20:42:48Z","updated_at":"2014-02-17T23:35:19Z","pushed_at":"2014-02-17T23:35:19Z","git_url":"git://github.com/keithrbennett/logging.git","ssh_url":"git@github.com:keithrbennett/logging.git","clone_url":"https://github.com/keithrbennett/logging.git","svn_url":"https://github.com/keithrbennett/logging","homepage":"http://logging.rubyforge.org/","size":1112,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":true,"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":"TwP:master","ref":"master","sha":"c1025b699f24a85946dfa3e391ca2f27791933e0","user":{"login":"TwP","id":6323,"avatar_url":"https://avatars.githubusercontent.com/u/6323?v=3","gravatar_id":"","url":"https://api.github.com/users/TwP","html_url":"https://github.com/TwP","followers_url":"https://api.github.com/users/TwP/followers","following_url":"https://api.github.com/users/TwP/following{/other_user}","gists_url":"https://api.github.com/users/TwP/gists{/gist_id}","starred_url":"https://api.github.com/users/TwP/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TwP/subscriptions","organizations_url":"https://api.github.com/users/TwP/orgs","repos_url":"https://api.github.com/users/TwP/repos","events_url":"https://api.github.com/users/TwP/events{/privacy}","received_events_url":"https://api.github.com/users/TwP/received_events","type":"User","site_admin":true},"repo":{"id":20669,"name":"logging","full_name":"TwP/logging","owner":{"login":"TwP","id":6323,"avatar_url":"https://avatars.githubusercontent.com/u/6323?v=3","gravatar_id":"","url":"https://api.github.com/users/TwP","html_url":"https://github.com/TwP","followers_url":"https://api.github.com/users/TwP/followers","following_url":"https://api.github.com/users/TwP/following{/other_user}","gists_url":"https://api.github.com/users/TwP/gists{/gist_id}","starred_url":"https://api.github.com/users/TwP/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TwP/subscriptions","organizations_url":"https://api.github.com/users/TwP/orgs","repos_url":"https://api.github.com/users/TwP/repos","events_url":"https://api.github.com/users/TwP/events{/privacy}","received_events_url":"https://api.github.com/users/TwP/received_events","type":"User","site_admin":true},"private":false,"html_url":"https://github.com/TwP/logging","description":"A flexible logging library for use in Ruby programs based on the design of Java's log4j library.","fork":false,"url":"https://api.github.com/repos/TwP/logging","forks_url":"https://api.github.com/repos/TwP/logging/forks","keys_url":"https://api.github.com/repos/TwP/logging/keys{/key_id}","collaborators_url":"https://api.github.com/repos/TwP/logging/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/TwP/logging/teams","hooks_url":"https://api.github.com/repos/TwP/logging/hooks","issue_events_url":"https://api.github.com/repos/TwP/logging/issues/events{/number}","events_url":"https://api.github.com/repos/TwP/logging/events","assignees_url":"https://api.github.com/repos/TwP/logging/assignees{/user}","branches_url":"https://api.github.com/repos/TwP/logging/branches{/branch}","tags_url":"https://api.github.com/repos/TwP/logging/tags","blobs_url":"https://api.github.com/repos/TwP/logging/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/TwP/logging/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/TwP/logging/git/refs{/sha}","trees_url":"https://api.github.com/repos/TwP/logging/git/trees{/sha}","statuses_url":"https://api.github.com/repos/TwP/logging/statuses/{sha}","languages_url":"https://api.github.com/repos/TwP/logging/languages","stargazers_url":"https://api.github.com/repos/TwP/logging/stargazers","contributors_url":"https://api.github.com/repos/TwP/logging/contributors","subscribers_url":"https://api.github.com/repos/TwP/logging/subscribers","subscription_url":"https://api.github.com/repos/TwP/logging/subscription","commits_url":"https://api.github.com/repos/TwP/logging/commits{/sha}","git_commits_url":"https://api.github.com/repos/TwP/logging/git/commits{/sha}","comments_url":"https://api.github.com/repos/TwP/logging/comments{/number}","issue_comment_url":"https://api.github.com/repos/TwP/logging/issues/comments{/number}","contents_url":"https://api.github.com/repos/TwP/logging/contents/{+path}","compare_url":"https://api.github.com/repos/TwP/logging/compare/{base}...{head}","merges_url":"https://api.github.com/repos/TwP/logging/merges","archive_url":"https://api.github.com/repos/TwP/logging/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/TwP/logging/downloads","issues_url":"https://api.github.com/repos/TwP/logging/issues{/number}","pulls_url":"https://api.github.com/repos/TwP/logging/pulls{/number}","milestones_url":"https://api.github.com/repos/TwP/logging/milestones{/number}","notifications_url":"https://api.github.com/repos/TwP/logging/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/TwP/logging/labels{/name}","releases_url":"https://api.github.com/repos/TwP/logging/releases{/id}","created_at":"2008-05-30T04:03:30Z","updated_at":"2015-03-28T04:44:57Z","pushed_at":"2015-03-28T04:45:23Z","git_url":"git://github.com/TwP/logging.git","ssh_url":"git@github.com:TwP/logging.git","clone_url":"https://github.com/TwP/logging.git","svn_url":"https://github.com/TwP/logging","homepage":"https://rubygems.org/gems/logging","size":1568,"stargazers_count":321,"watchers_count":321,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":55,"mirror_url":null,"open_issues_count":8,"forks":55,"open_issues":8,"watchers":321,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/TwP/logging/pulls/80"},"html":{"href":"https://github.com/TwP/logging/pull/80"},"issue":{"href":"https://api.github.com/repos/TwP/logging/issues/80"},"comments":{"href":"https://api.github.com/repos/TwP/logging/issues/80/comments"},"review_comments":{"href":"https://api.github.com/repos/TwP/logging/pulls/80/comments"},"review_comment":{"href":"https://api.github.com/repos/TwP/logging/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/TwP/logging/pulls/80/commits"},"statuses":{"href":"https://api.github.com/repos/TwP/logging/statuses/2c665d85367ef4b57f38232e4bb26634a7c17287"}}}}