inform 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +15 -0
- data/.gitignore +1 -0
- data/README.md +30 -15
- data/lib/inform/version.rb +1 -1
- data/lib/inform.rb +16 -2
- data/spec/inform_spec.rb +18 -9
- metadata +59 -81
    
        checksums.yaml
    ADDED
    
    | @@ -0,0 +1,15 @@ | |
| 1 | 
            +
            ---
         | 
| 2 | 
            +
            !binary "U0hBMQ==":
         | 
| 3 | 
            +
              metadata.gz: !binary |-
         | 
| 4 | 
            +
                ZTRmYzY5YmIwZDNiY2EyYWExNjViNGE5ZjcxNDdkNjU3MjJmNTNiYg==
         | 
| 5 | 
            +
              data.tar.gz: !binary |-
         | 
| 6 | 
            +
                YTRiNGZmZWJiZTA3ZjU4OTM5MWYxODc2MmRjMjM4MDlkNDU1OTZhZQ==
         | 
| 7 | 
            +
            !binary "U0hBNTEy":
         | 
| 8 | 
            +
              metadata.gz: !binary |-
         | 
| 9 | 
            +
                YTg3OGU3NzBhMDI0ODM5MDZmMGFjOWU1MmMzZTRlNjdjN2RlYjAzNWJlNjc1
         | 
| 10 | 
            +
                MGU5ZjVhMGM3YWQ0NTg2ZWEwZDY4ODA3NTlmNTAwYWNjNjE5MTQ0NzFjMTJj
         | 
| 11 | 
            +
                MTQ2NjczMWZiZGM3MzZkMDM5MWYzMGE5MjQ4OGVmMjdmZjRiODM=
         | 
| 12 | 
            +
              data.tar.gz: !binary |-
         | 
| 13 | 
            +
                MzZmZGE2ZDM4YmJiNTdiM2JjYTk1OTE1NTIwYWRhZGVmNTU1ZWMzZjE0NDRl
         | 
| 14 | 
            +
                YmExZWE2ZTQ3NjVlMjFhNDU3ZjdhZDY2OTVkYzc1MzZmNGZkMjczODUwNTU0
         | 
| 15 | 
            +
                NmE4YThmYjc1OGEwYjQxMDE1OTA3N2MwNWQ4OTFmYzFlMzc1NTY=
         | 
    
        data/.gitignore
    CHANGED
    
    
    
        data/README.md
    CHANGED
    
    | @@ -1,25 +1,40 @@ | |
| 1 1 | 
             
            # Inform
         | 
| 2 2 |  | 
| 3 3 | 
             
            **Inform** prints colourised, interactive logging output to the console.
         | 
| 4 | 
            +
            It includes support for timings and thread-local prefixes.
         | 
| 4 5 |  | 
| 5 6 | 
             
            For example:
         | 
| 6 7 |  | 
| 7 | 
            -
             | 
| 8 | 
            -
             | 
| 9 | 
            -
             | 
| 10 | 
            -
                end
         | 
| 11 | 
            -
                
         | 
| 12 | 
            -
                Inform.info("Frozbot is %{name}", :name => frozbot.name)
         | 
| 8 | 
            +
            ``` ruby
         | 
| 9 | 
            +
            # Controllable log level filtering
         | 
| 10 | 
            +
            Inform.level = :info
         | 
| 13 11 |  | 
| 14 | 
            -
             | 
| 12 | 
            +
            # Accept a block, print timing information once completed if > 0.1s
         | 
| 13 | 
            +
            frozbot = Inform.info("Initializing the frozbot") do
         | 
| 14 | 
            +
              Frozbot.new
         | 
| 15 | 
            +
              sleep 1
         | 
| 16 | 
            +
            end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
            # Other log levels than info
         | 
| 19 | 
            +
            Inform.level = :debug
         | 
| 20 | 
            +
            Inform.debug("Madness")
         | 
| 21 | 
            +
            Inform.warning("and")
         | 
| 22 | 
            +
            Inform.error("Nonsense")
         | 
| 15 23 |  | 
| 16 | 
            -
             | 
| 17 | 
            -
             | 
| 24 | 
            +
            # Thread-local log prefixing
         | 
| 25 | 
            +
            Thread.current[:inform] = '1'
         | 
| 26 | 
            +
            Inform.info("Frozbot is %{name}", :name => frozbot.name)
         | 
| 27 | 
            +
            ```
         | 
| 18 28 |  | 
| 19 | 
            -
             | 
| 29 | 
            +
            Will print:
         | 
| 20 30 |  | 
| 21 | 
            -
             | 
| 22 | 
            -
             | 
| 31 | 
            +
            ```
         | 
| 32 | 
            +
            >>> Initializing the frozbot : Done (1.00s)
         | 
| 33 | 
            +
                Madness
         | 
| 34 | 
            +
            WARNING: and
         | 
| 35 | 
            +
            ERROR: Nonsense
         | 
| 36 | 
            +
            1 *** Frozbot is myfrozbot
         | 
| 37 | 
            +
            ```
         | 
| 23 38 |  | 
| 24 39 | 
             
            ### TODO
         | 
| 25 40 |  | 
| @@ -27,12 +42,12 @@ requirements, etc will change. | |
| 27 42 | 
             
             * Refactor tests
         | 
| 28 43 | 
             
             * Colourisation isn't tested at all - should it be?
         | 
| 29 44 | 
             
             * RDoc
         | 
| 30 | 
            -
             | 
| 45 | 
            +
             | 
| 31 46 | 
             
            ## License
         | 
| 32 47 |  | 
| 33 48 | 
             
            (The MIT License)
         | 
| 34 49 |  | 
| 35 | 
            -
            Copyright (c) 2011 PlayUp
         | 
| 50 | 
            +
            Copyright (c) 2011 PlayUp, 2012-13 Michael Pearson
         | 
| 36 51 |  | 
| 37 52 | 
             
            Permission is hereby granted, free of charge, to any person obtaining
         | 
| 38 53 | 
             
            a copy of this software and associated documentation files (the
         | 
| @@ -51,4 +66,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | |
| 51 66 | 
             
            IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
         | 
| 52 67 | 
             
            CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
         | 
| 53 68 | 
             
            TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
         | 
| 54 | 
            -
            SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
         | 
| 69 | 
            +
            SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
         | 
    
        data/lib/inform/version.rb
    CHANGED
    
    
    
        data/lib/inform.rb
    CHANGED
    
    | @@ -21,6 +21,14 @@ class Inform | |
| 21 21 |  | 
| 22 22 | 
             
              class << self
         | 
| 23 23 |  | 
| 24 | 
            +
                def thread_prefix= prefix
         | 
| 25 | 
            +
                  Thread.current[:inform_prefix] = prefix
         | 
| 26 | 
            +
                end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                def thread_prefix
         | 
| 29 | 
            +
                  Thread.current[:inform_prefix]
         | 
| 30 | 
            +
                end
         | 
| 31 | 
            +
             | 
| 24 32 | 
             
                def level
         | 
| 25 33 | 
             
                  @level.nil? ? DEFAULT_LOG_LEVEL : @level
         | 
| 26 34 | 
             
                end
         | 
| @@ -35,13 +43,15 @@ class Inform | |
| 35 43 | 
             
                end
         | 
| 36 44 |  | 
| 37 45 | 
             
                def info(message, args=nil)
         | 
| 46 | 
            +
             | 
| 38 47 | 
             
                  if block_given?
         | 
| 39 48 | 
             
                    start = Time.now
         | 
| 40 | 
            -
                     | 
| 49 | 
            +
                    smart_newlines = thread_prefix.nil?
         | 
| 50 | 
            +
                    log(:info, ">>> " + color_args(message, args, GREEN) + " : ", :no_newline => smart_newlines)
         | 
| 41 51 | 
             
                    ret = yield
         | 
| 42 52 | 
             
                    elapsed = Time.now - start
         | 
| 43 53 | 
             
                    message = elapsed > 0.01 ? "Done. (#{sprintf '%.2f', elapsed}s)" : 'Done.'
         | 
| 44 | 
            -
                    log(:info, color(message, GREEN), :continue_line =>  | 
| 54 | 
            +
                    log(:info, color(message, GREEN), :continue_line => smart_newlines, :prefix => '>>> ')
         | 
| 45 55 | 
             
                    ret
         | 
| 46 56 | 
             
                  else
         | 
| 47 57 | 
             
                    log(:info, "*** " + color_args(message, args, GREEN))
         | 
| @@ -74,6 +84,10 @@ class Inform | |
| 74 84 | 
             
                      @need_newline = false
         | 
| 75 85 | 
             
                    end
         | 
| 76 86 | 
             
                    message += "\n" if end_with_newline
         | 
| 87 | 
            +
                    if Thread.current.key? :inform_prefix
         | 
| 88 | 
            +
                      message = Thread.current[:inform_prefix].to_s + ' ' + message
         | 
| 89 | 
            +
                    end
         | 
| 90 | 
            +
             | 
| 77 91 | 
             
                    $stdout.print message
         | 
| 78 92 | 
             
                    $stdout.flush
         | 
| 79 93 | 
             
                  end
         | 
    
        data/spec/inform_spec.rb
    CHANGED
    
    | @@ -10,6 +10,15 @@ def should_print method | |
| 10 10 | 
             
                  $stdout.should_receive(:print).with(/hello.+hey.+you.+goodbye/)
         | 
| 11 11 | 
             
                  Inform.send(method, "hello %{a} %{b} goodbye", :a => 'hey', :b => 'you')
         | 
| 12 12 | 
             
                end
         | 
| 13 | 
            +
                it "should prefix with the :inform thread variable if present" do
         | 
| 14 | 
            +
                  begin
         | 
| 15 | 
            +
                    Inform.thread_prefix = 'hi'
         | 
| 16 | 
            +
                    $stdout.should_receive(:print).with(/^hi .+blank/)
         | 
| 17 | 
            +
                    Inform.send(method, "blank")
         | 
| 18 | 
            +
                  ensure
         | 
| 19 | 
            +
                    Inform.thread_prefix = nil
         | 
| 20 | 
            +
                  end
         | 
| 21 | 
            +
                end
         | 
| 13 22 | 
             
              end
         | 
| 14 23 | 
             
            end
         | 
| 15 24 |  | 
| @@ -57,35 +66,35 @@ describe Inform do | |
| 57 66 | 
             
                  Inform.level = :info
         | 
| 58 67 | 
             
                  Inform.level.should == :info
         | 
| 59 68 | 
             
                end
         | 
| 60 | 
            -
             | 
| 69 | 
            +
             | 
| 61 70 | 
             
                it "should not allow us to set a log level that isn't recognized" do
         | 
| 62 71 | 
             
                  lambda {Inform.level = :warble}.should raise_error /unrecognized/i
         | 
| 63 72 | 
             
                end
         | 
| 64 73 | 
             
              end
         | 
| 65 | 
            -
             | 
| 74 | 
            +
             | 
| 66 75 | 
             
              context "with log level debug" do
         | 
| 67 76 | 
             
                before { Inform.level = :debug }
         | 
| 68 77 |  | 
| 69 | 
            -
                should_print :debug | 
| 70 | 
            -
                should_print :info | 
| 78 | 
            +
                should_print :debug
         | 
| 79 | 
            +
                should_print :info
         | 
| 71 80 | 
             
                should_accept_block :info
         | 
| 72 81 | 
             
                # should_accept_block :debug
         | 
| 73 82 |  | 
| 74 83 | 
             
                should_print :warning
         | 
| 75 84 | 
             
                should_print :error
         | 
| 76 85 | 
             
              end
         | 
| 77 | 
            -
             | 
| 86 | 
            +
             | 
| 78 87 | 
             
              context "with log level set to :info" do
         | 
| 79 88 | 
             
                before { Inform.level = :info }
         | 
| 80 89 | 
             
                should_not_print :debug
         | 
| 81 90 | 
             
                should_print :info
         | 
| 82 91 | 
             
                should_accept_block :info
         | 
| 83 92 | 
             
                # should_accept_block :debug
         | 
| 84 | 
            -
             | 
| 93 | 
            +
             | 
| 85 94 | 
             
                should_print :warning
         | 
| 86 95 | 
             
                should_print :error
         | 
| 87 96 | 
             
              end
         | 
| 88 | 
            -
             | 
| 97 | 
            +
             | 
| 89 98 | 
             
              context "with log level set to :warning" do
         | 
| 90 99 | 
             
                before { Inform.level = :warning }
         | 
| 91 100 | 
             
                should_not_print :debug
         | 
| @@ -100,11 +109,11 @@ describe Inform do | |
| 100 109 | 
             
                should_not_print :info
         | 
| 101 110 | 
             
                should_not_print :warning
         | 
| 102 111 | 
             
                should_print :error
         | 
| 103 | 
            -
             | 
| 112 | 
            +
             | 
| 104 113 | 
             
                describe :info do
         | 
| 105 114 | 
             
                  it "should still execute the code block" do
         | 
| 106 115 | 
             
                    Inform.info("") { 'hello' }.should == 'hello'
         | 
| 107 116 | 
             
                  end
         | 
| 108 117 | 
             
                end
         | 
| 109 118 | 
             
              end
         | 
| 110 | 
            -
            end
         | 
| 119 | 
            +
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,78 +1,66 @@ | |
| 1 | 
            -
            --- !ruby/object:Gem::Specification | 
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: inform
         | 
| 3 | 
            -
            version: !ruby/object:Gem::Version | 
| 4 | 
            -
               | 
| 5 | 
            -
              prerelease: 
         | 
| 6 | 
            -
              segments: 
         | 
| 7 | 
            -
              - 0
         | 
| 8 | 
            -
              - 0
         | 
| 9 | 
            -
              - 6
         | 
| 10 | 
            -
              version: 0.0.6
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            +
              version: 0.0.7
         | 
| 11 5 | 
             
            platform: ruby
         | 
| 12 | 
            -
            authors: | 
| 6 | 
            +
            authors:
         | 
| 13 7 | 
             
            - Michael Pearson
         | 
| 14 8 | 
             
            - Chris Ottrey
         | 
| 15 9 | 
             
            autorequire: 
         | 
| 16 10 | 
             
            bindir: bin
         | 
| 17 11 | 
             
            cert_chain: []
         | 
| 18 | 
            -
             | 
| 19 | 
            -
             | 
| 20 | 
            -
             | 
| 21 | 
            -
             | 
| 22 | 
            -
             | 
| 23 | 
            -
              prerelease: false
         | 
| 24 | 
            -
              requirement: &id001 !ruby/object:Gem::Requirement 
         | 
| 25 | 
            -
                none: false
         | 
| 26 | 
            -
                requirements: 
         | 
| 12 | 
            +
            date: 2013-05-04 00:00:00.000000000 Z
         | 
| 13 | 
            +
            dependencies:
         | 
| 14 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 15 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 16 | 
            +
                requirements:
         | 
| 27 17 | 
             
                - - ~>
         | 
| 28 | 
            -
                  - !ruby/object:Gem::Version | 
| 29 | 
            -
                     | 
| 30 | 
            -
             | 
| 31 | 
            -
             | 
| 32 | 
            -
             | 
| 33 | 
            -
             | 
| 18 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 19 | 
            +
                    version: 2.6.0
         | 
| 20 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 21 | 
            +
                requirements:
         | 
| 22 | 
            +
                - - ~>
         | 
| 23 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 34 24 | 
             
                    version: 2.6.0
         | 
| 35 25 | 
             
              type: :development
         | 
| 36 | 
            -
              version_requirements: *id001
         | 
| 37 | 
            -
            - !ruby/object:Gem::Dependency 
         | 
| 38 | 
            -
              name: rake
         | 
| 39 26 | 
             
              prerelease: false
         | 
| 40 | 
            -
               | 
| 41 | 
            -
             | 
| 42 | 
            -
             | 
| 43 | 
            -
                 | 
| 44 | 
            -
             | 
| 45 | 
            -
             | 
| 46 | 
            -
                     | 
| 47 | 
            -
             | 
| 48 | 
            -
             | 
| 27 | 
            +
              name: rspec
         | 
| 28 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 29 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 30 | 
            +
                requirements:
         | 
| 31 | 
            +
                - - ! '>='
         | 
| 32 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 33 | 
            +
                    version: '0'
         | 
| 34 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 35 | 
            +
                requirements:
         | 
| 36 | 
            +
                - - ! '>='
         | 
| 37 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 38 | 
            +
                    version: '0'
         | 
| 49 39 | 
             
              type: :development
         | 
| 50 | 
            -
              version_requirements: *id002
         | 
| 51 | 
            -
            - !ruby/object:Gem::Dependency 
         | 
| 52 | 
            -
              name: gem-release
         | 
| 53 40 | 
             
              prerelease: false
         | 
| 54 | 
            -
               | 
| 55 | 
            -
             | 
| 56 | 
            -
             | 
| 57 | 
            -
                 | 
| 58 | 
            -
             | 
| 59 | 
            -
             | 
| 60 | 
            -
                     | 
| 61 | 
            -
             | 
| 62 | 
            -
             | 
| 41 | 
            +
              name: rake
         | 
| 42 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 43 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 44 | 
            +
                requirements:
         | 
| 45 | 
            +
                - - ! '>='
         | 
| 46 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 47 | 
            +
                    version: '0'
         | 
| 48 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 49 | 
            +
                requirements:
         | 
| 50 | 
            +
                - - ! '>='
         | 
| 51 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 52 | 
            +
                    version: '0'
         | 
| 63 53 | 
             
              type: :development
         | 
| 64 | 
            -
               | 
| 54 | 
            +
              prerelease: false
         | 
| 55 | 
            +
              name: gem-release
         | 
| 65 56 | 
             
            description: Interactive, colourised logging
         | 
| 66 | 
            -
            email: | 
| 57 | 
            +
            email:
         | 
| 67 58 | 
             
            - mipearson@gmail.com
         | 
| 68 | 
            -
            -  | 
| 59 | 
            +
            - ''
         | 
| 69 60 | 
             
            executables: []
         | 
| 70 | 
            -
             | 
| 71 61 | 
             
            extensions: []
         | 
| 72 | 
            -
             | 
| 73 62 | 
             
            extra_rdoc_files: []
         | 
| 74 | 
            -
             | 
| 75 | 
            -
            files: 
         | 
| 63 | 
            +
            files:
         | 
| 76 64 | 
             
            - .gitignore
         | 
| 77 65 | 
             
            - Gemfile
         | 
| 78 66 | 
             
            - README.md
         | 
| @@ -85,37 +73,27 @@ files: | |
| 85 73 | 
             
            - spec/spec_helper.rb
         | 
| 86 74 | 
             
            homepage: https://github.com/mipearson/inform
         | 
| 87 75 | 
             
            licenses: []
         | 
| 88 | 
            -
             | 
| 76 | 
            +
            metadata: {}
         | 
| 89 77 | 
             
            post_install_message: 
         | 
| 90 78 | 
             
            rdoc_options: []
         | 
| 91 | 
            -
             | 
| 92 | 
            -
            require_paths: 
         | 
| 79 | 
            +
            require_paths:
         | 
| 93 80 | 
             
            - lib
         | 
| 94 | 
            -
            required_ruby_version: !ruby/object:Gem::Requirement | 
| 95 | 
            -
               | 
| 96 | 
            -
               | 
| 97 | 
            -
             | 
| 98 | 
            -
             | 
| 99 | 
            -
             | 
| 100 | 
            -
             | 
| 101 | 
            -
             | 
| 102 | 
            -
             | 
| 103 | 
            -
             | 
| 104 | 
            -
              none: false
         | 
| 105 | 
            -
              requirements: 
         | 
| 106 | 
            -
              - - ">="
         | 
| 107 | 
            -
                - !ruby/object:Gem::Version 
         | 
| 108 | 
            -
                  hash: 3
         | 
| 109 | 
            -
                  segments: 
         | 
| 110 | 
            -
                  - 0
         | 
| 111 | 
            -
                  version: "0"
         | 
| 81 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 82 | 
            +
              requirements:
         | 
| 83 | 
            +
              - - ! '>='
         | 
| 84 | 
            +
                - !ruby/object:Gem::Version
         | 
| 85 | 
            +
                  version: '0'
         | 
| 86 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 87 | 
            +
              requirements:
         | 
| 88 | 
            +
              - - ! '>='
         | 
| 89 | 
            +
                - !ruby/object:Gem::Version
         | 
| 90 | 
            +
                  version: '0'
         | 
| 112 91 | 
             
            requirements: []
         | 
| 113 | 
            -
             | 
| 114 92 | 
             
            rubyforge_project: 
         | 
| 115 | 
            -
            rubygems_version:  | 
| 93 | 
            +
            rubygems_version: 2.0.3
         | 
| 116 94 | 
             
            signing_key: 
         | 
| 117 | 
            -
            specification_version:  | 
| 95 | 
            +
            specification_version: 4
         | 
| 118 96 | 
             
            summary: Interactive, colourised logging
         | 
| 119 | 
            -
            test_files: | 
| 97 | 
            +
            test_files:
         | 
| 120 98 | 
             
            - spec/inform_spec.rb
         | 
| 121 99 | 
             
            - spec/spec_helper.rb
         |