object_identifier 0.0.1 → 0.0.2
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 +4 -4
 - data/README.md +96 -0
 - data/lib/object_identifier/identifier.rb +1 -6
 - data/lib/object_identifier/version.rb +1 -1
 - metadata +5 -4
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 157f8efe2cfccf189c024f9dbf79bd406bcd8161
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: bf91af5bbe21d2ca45cc4020fe6db71d62f83bce
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 6e770c731b11d1789c09682845177510a6dbc0feb8f841f13955147dba10686f1ba0ecaecd31b11f4db05e320d72adb2c804c0e4333fcf211126c08dbfc6fe0f
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 15cae1fb559f72d069f45a95072859b056290c278768ab318fbad9d9ad20a5712144961763f8ceb8eff9b80e9d8c243680e5d4631f0ef22391b5d6200510293b
         
     | 
    
        data/README.md
    ADDED
    
    | 
         @@ -0,0 +1,96 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # Object Identifier
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            [](http://badge.fury.io/rb/object_identifier)
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            Object Identifier allows quick, easy, and uniform identification of an object
         
     | 
| 
      
 6 
     | 
    
         
            +
            by inspecting its class name and any desirable attributes/methods. This is great
         
     | 
| 
      
 7 
     | 
    
         
            +
            for logging, notifications or any other purpose.
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
            For example, instead of typing out string interpolations such as
         
     | 
| 
      
 10 
     | 
    
         
            +
            `"#{some_object.class.name}[id:#{some_object.id}, name:'#{some_object.name}']"`
         
     | 
| 
      
 11 
     | 
    
         
            +
            all over the place in controllers or in rescue blocks in models, etc., you can
         
     | 
| 
      
 12 
     | 
    
         
            +
            now just use `"#{some_object.identify(:id, :name)}"`.
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
            ## Compatibility
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
            Tested with:
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
            * Ruby: MRI 2.0.0
         
     | 
| 
      
 20 
     | 
    
         
            +
            * Rails: 4.0.1
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
            ## Installation
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
            Add this line to your application's Gemfile:
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 27 
     | 
    
         
            +
            gem "object_identifier"
         
     | 
| 
      
 28 
     | 
    
         
            +
            ```
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
            And then execute:
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 33 
     | 
    
         
            +
            bundle
         
     | 
| 
      
 34 
     | 
    
         
            +
            ```
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
            ## Usage
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
            <b>Defaults</b>
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
            Outputs the `id` attribute by default, if possible and if no other attributes
         
     | 
| 
      
 41 
     | 
    
         
            +
            are given:
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 44 
     | 
    
         
            +
            some_object.identify  # => Movie[id:1]
         
     | 
| 
      
 45 
     | 
    
         
            +
            ```
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
            Also works with methods:
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 50 
     | 
    
         
            +
            some_object.identify(:get_rating)  # => Movie[get_rating:"7/10"]
         
     | 
| 
      
 51 
     | 
    
         
            +
            ```
         
     | 
| 
      
 52 
     | 
    
         
            +
             
     | 
| 
      
 53 
     | 
    
         
            +
            <b>Unknown Attributes/Methods</b>
         
     | 
| 
      
 54 
     | 
    
         
            +
             
     | 
| 
      
 55 
     | 
    
         
            +
            If the object doesn't respond to a specified attribute/method it is simply
         
     | 
| 
      
 56 
     | 
    
         
            +
            ignored:
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
      
 58 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 59 
     | 
    
         
            +
            some_object.identify(:gobble_gobble, :id)  # => Movie[id:1]
         
     | 
| 
      
 60 
     | 
    
         
            +
            ```
         
     | 
| 
      
 61 
     | 
    
         
            +
             
     | 
| 
      
 62 
     | 
    
         
            +
            <b>Collections</b>
         
     | 
| 
      
 63 
     | 
    
         
            +
             
     | 
| 
      
 64 
     | 
    
         
            +
            Works great with collections:
         
     | 
| 
      
 65 
     | 
    
         
            +
             
     | 
| 
      
 66 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 67 
     | 
    
         
            +
            [some_object, some_other_object].identify(:id, :name)
         
     | 
| 
      
 68 
     | 
    
         
            +
              # => Movie[id:1, name:"Pi"], Contact[id:23, name:"Bob"]
         
     | 
| 
      
 69 
     | 
    
         
            +
            ```
         
     | 
| 
      
 70 
     | 
    
         
            +
             
     | 
| 
      
 71 
     | 
    
         
            +
            Also allows limiting of results:
         
     | 
| 
      
 72 
     | 
    
         
            +
             
     | 
| 
      
 73 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 74 
     | 
    
         
            +
            [some_object, some_other_object].identify(:id, :name, limit: 1)
         
     | 
| 
      
 75 
     | 
    
         
            +
              # => Movie[id:1, name:"Pi"], ... (1 more)
         
     | 
| 
      
 76 
     | 
    
         
            +
            ```
         
     | 
| 
      
 77 
     | 
    
         
            +
             
     | 
| 
      
 78 
     | 
    
         
            +
            <b>Overriding the Class Name</b>
         
     | 
| 
      
 79 
     | 
    
         
            +
             
     | 
| 
      
 80 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 81 
     | 
    
         
            +
            some_object.identify(klass: "MyMovie")       # => MyMovie[id:1]
         
     | 
| 
      
 82 
     | 
    
         
            +
            some_object.identify(klass: nil)             # => [id:1]
         
     | 
| 
      
 83 
     | 
    
         
            +
            delayed_job.identify(klass: "Delayed::Job")  # => Delayed::Job[id:1]
         
     | 
| 
      
 84 
     | 
    
         
            +
            ```
         
     | 
| 
      
 85 
     | 
    
         
            +
             
     | 
| 
      
 86 
     | 
    
         
            +
            <b>Nils and Empty Collections</b>
         
     | 
| 
      
 87 
     | 
    
         
            +
             
     | 
| 
      
 88 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 89 
     | 
    
         
            +
            nil.identify(:id, :name)  # => [no objects]
         
     | 
| 
      
 90 
     | 
    
         
            +
            [].identify               # => [no objects]
         
     | 
| 
      
 91 
     | 
    
         
            +
            ```
         
     | 
| 
      
 92 
     | 
    
         
            +
             
     | 
| 
      
 93 
     | 
    
         
            +
            ## Authors
         
     | 
| 
      
 94 
     | 
    
         
            +
             
     | 
| 
      
 95 
     | 
    
         
            +
            - Paul Dobbins
         
     | 
| 
      
 96 
     | 
    
         
            +
            - Evan Sherwood
         
     | 
| 
         @@ -25,12 +25,7 @@ module ObjectIdentifier 
     | 
|
| 
       25 
25 
     | 
    
         
             
                #   ObjectIdentifier::Identifier.identify(%w(1 2 3), :to_i, :to_f) # => "String[to_i:1, to_f:1.0], String[to_i:2, to_f:2.0], String[to_i:3, to_f:3.0]"
         
     | 
| 
       26 
26 
     | 
    
         
             
                #   ObjectIdentifier::Identifier.identify((1..10).to_a, :to_f, limit: 2) # => "Fixnum[to_f:1.0], Fixnum[to_f:2.0], ... (8 more)"
         
     | 
| 
       27 
27 
     | 
    
         
             
                def self.identify(obj, *args)
         
     | 
| 
       28 
     | 
    
         
            -
                  obj  
     | 
| 
       29 
     | 
    
         
            -
                          obj.to_ary
         
     | 
| 
       30 
     | 
    
         
            -
                        else
         
     | 
| 
       31 
     | 
    
         
            -
                          [obj]
         
     | 
| 
       32 
     | 
    
         
            -
                        end
         
     | 
| 
       33 
     | 
    
         
            -
                  new(obj, *args).to_s
         
     | 
| 
      
 28 
     | 
    
         
            +
                  new(Array.wrap(obj), *args).to_s
         
     | 
| 
       34 
29 
     | 
    
         
             
                end
         
     | 
| 
       35 
30 
     | 
    
         | 
| 
       36 
31 
     | 
    
         
             
                def initialize(objects, *args)
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: object_identifier
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.0.2
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Paul Dobbins
         
     | 
| 
         @@ -9,7 +9,7 @@ authors: 
     | 
|
| 
       9 
9 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       10 
10 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       11 
11 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       12 
     | 
    
         
            -
            date: 2013-11- 
     | 
| 
      
 12 
     | 
    
         
            +
            date: 2013-11-20 00:00:00.000000000 Z
         
     | 
| 
       13 
13 
     | 
    
         
             
            dependencies:
         
     | 
| 
       14 
14 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       15 
15 
     | 
    
         
             
              name: rails
         
     | 
| 
         @@ -17,14 +17,14 @@ dependencies: 
     | 
|
| 
       17 
17 
     | 
    
         
             
                requirements:
         
     | 
| 
       18 
18 
     | 
    
         
             
                - - ~>
         
     | 
| 
       19 
19 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       20 
     | 
    
         
            -
                    version: 4.0. 
     | 
| 
      
 20 
     | 
    
         
            +
                    version: 4.0.0
         
     | 
| 
       21 
21 
     | 
    
         
             
              type: :runtime
         
     | 
| 
       22 
22 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       23 
23 
     | 
    
         
             
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
       24 
24 
     | 
    
         
             
                requirements:
         
     | 
| 
       25 
25 
     | 
    
         
             
                - - ~>
         
     | 
| 
       26 
26 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       27 
     | 
    
         
            -
                    version: 4.0. 
     | 
| 
      
 27 
     | 
    
         
            +
                    version: 4.0.0
         
     | 
| 
       28 
28 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       29 
29 
     | 
    
         
             
              name: naught
         
     | 
| 
       30 
30 
     | 
    
         
             
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
         @@ -110,6 +110,7 @@ files: 
     | 
|
| 
       110 
110 
     | 
    
         
             
            - lib/object_identifier.rb
         
     | 
| 
       111 
111 
     | 
    
         
             
            - MIT-LICENSE
         
     | 
| 
       112 
112 
     | 
    
         
             
            - Rakefile
         
     | 
| 
      
 113 
     | 
    
         
            +
            - README.md
         
     | 
| 
       113 
114 
     | 
    
         
             
            - test/core_ext/object_test.rb
         
     | 
| 
       114 
115 
     | 
    
         
             
            - test/core_ext/string_test.rb
         
     | 
| 
       115 
116 
     | 
    
         
             
            - test/core_ext/symbol_test.rb
         
     |