Giter VIP home page Giter VIP logo

uuidtools's Introduction

Build Status

UUIDTools

Homepage
sporkmonger/uuidtools
Author
Bob Aman
Copyright
Copyright ยฉ 2005-2014 Bob Aman
License
Apache 2.0

Description

UUIDTools was designed to be a simple library for generating any of the various types of UUIDs. It conforms to RFC 4122 whenever possible.

Reference

  • {UUIDTools::UUID}

Example usage

require "uuidtools"

UUIDTools::UUID.md5_create(UUIDTools::UUID_DNS_NAMESPACE, "www.widgets.com")
# => #<UUID:0x287576 UUID:3d813cbb-47fb-32ba-91df-831e1593ac29>
UUIDTools::UUID.sha1_create(UUIDTools::UUID_DNS_NAMESPACE, "www.widgets.com")
# => #<UUID:0x2a0116 UUID:21f7f8de-8051-5b89-8680-0195ef798b6a>
UUIDTools::UUID.timestamp_create
# => #<UUID:0x2adfdc UUID:64a5189c-25b3-11da-a97b-00c04fd430c8>
UUIDTools::UUID.random_create
# => #<UUID:0x19013a UUID:984265dc-4200-4f02-ae70-fe4f48964159>

Install

$ sudo gem install uuidtools

uuidtools's People

Contributors

benders avatar flameeyes avatar kevin-at-reflexion avatar markllama avatar monde avatar pikachuexe avatar pszals avatar sodabrew avatar sporkmonger avatar tlunter avatar voltechs avatar zeha avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

uuidtools's Issues

Release new gem version with fix for ip command?

Commit 8c0d99d fixes support for getting the mac address through the ip command. After patching it myself, I figured out the solution was already in master. Maybe this fix deserves a new gem release, as the ip command will be more and more common?

MAC address fetching fails on Linux if /proc is unaccessible

Hello,

I've found in Gentoo a bug where uuidtools does not pass tests because it can't find a MAC address for the host. -The reason is relatively simple: the host has no IPv4 so the trick with ifconfig+arp will fail.- Edit: I read the logic wrong, the arp trick is for Solaris. There still is some problems as ifconfig on a hardened LXC guest does not report the ethernet address, trying to find out why right now.

I'm working on changing the code to look for the ethernet address on the ifconfig output directly โ€” it's going to be slightly tricky because there are two possible output styles for ifconfig, and at some point it might even disappear in favour of the ip command.

Anyway I'll submit a patch shortly.

to_s references internal state

to_s on a uuid object seems to reference internal state, for example:

u = UUIDTools::UUID.random_create
>> #<UUID:0x1ab59b7df8 UUID:c08bf74a-98c5-4d82-bb96-e8dbaa1e1dfb>

u.to_s.gsub! '-', '/'
=> "c08bf74a/98c5/4d82/bb96/e8dbaa1e1dfb"

u
=> #<UUID:0x1ab59b7df8 UUID:c08bf74a/98c5/4d82/bb96/e8dbaa1e1dfb>

I get around the issue by using dup:

u.to_s.dup.gsub! '-', '/'

The results of to_s should be immutable with respect to the uuid object state.

New Gem Build

There have been a couple of bug fixes since the last gem version. Any chance of there being new one released?

Tests fail after commit b0e3ce1 on ubuntu 12.04.2

Hi,

I open a new issue since the rspec output as changed (from this previous issue #12 ):

I copy paste the entire output :

Warning: cannot open /proc/net/dev (No such file or directory). Limited output.
F...............*............Warning: cannot open /proc/net/dev (No such file or directory). Limited output.
F..................F...............

Pending:
  UUIDTools::UUID before obtaining a MAC address should return the output of the ifconfig program
    # I'm not quite sure how to mock backticks
    # ./spec/uuidtools/mac_address_spec.rb:418

Failures:

  1) UUIDTools::UUID when obtaining a MAC address should obtain a MAC address
     Failure/Error: @mac_address.should_not be_nil
       expected: not nil
            got: nil
     # ./spec/uuidtools/mac_address_spec.rb:243:in `block (2 levels) in <top (required)>'

  2) UUIDTools::UUID when generating should correctly generate timestamp variant UUIDs
     Failure/Error: UUIDTools::UUID.timestamp_create.should_not be_random_node_id
       expected random_node_id? to return false, got true
     # ./spec/uuidtools/uuid_creation_spec.rb:17:in `block (2 levels) in <top (required)>'

  3) UUIDTools::UUID when parsing should not treat a timestamp version UUID as a random node UUID
     Failure/Error: UUIDTools::UUID.timestamp_create.should_not be_random_node_id
       expected random_node_id? to return false, got true
     # ./spec/uuidtools/uuid_parsing_spec.rb:27:in `block (2 levels) in <top (required)>'

Finished in 0.1865 seconds
64 examples, 3 failures, 1 pending

Failed examples:

rspec ./spec/uuidtools/mac_address_spec.rb:241 # UUIDTools::UUID when obtaining a MAC address should obtain a MAC address
rspec ./spec/uuidtools/uuid_creation_spec.rb:16 # UUIDTools::UUID when generating should correctly generate timestamp variant UUIDs
rspec ./spec/uuidtools/uuid_parsing_spec.rb:26 # UUIDTools::UUID when parsing should not treat a timestamp version UUID as a random node UUID

Missing ip & ifconfig causes mysterious errors

I used a new docker image to boot up an older Rails application that depends on the uuidtools gem, specifically the UUIDTools::UUID.timestamp_create method. After the image update, I was seeing a these errors in rspec tests:

      Failure/Error: uuid { UUIDTools::UUID.timestamp_create.to_s }
      
      NoMethodError:
        undefined method `[]' for nil:NilClass

This comes from the assumption that /sbin/ip will exist, at

ifconfig_path = "#{UUID.ip_path} addr list"
. It would be good if it throws a more informative error instead.

My solution was to add the OS package that included the ifconfig command (which was smaller than the one that included the ip command).

Ruby 1.9 on windows fails

Noticed this in the log: 'which' is not recognized as an internal or external command,
operable program or batch file.

Changed line 418 to:
if (os_platform =~ /win/ && !(os_platform =~ /darwin/)) || os_platform =~ /w32/

That fixes it.

Windows still broken

Here's the new fix, next time I'll just fork this and let you pull in the fix if there is anything else:

Line 415:
windoze = os_platform =~ (/win/ && !(os_platform =~ /darwin/)) ||
os_platform =~ /w32/
if windoze
script_in_path = true
.....

Line 446ish:
elsif windoze
begin
ifconfig_output = ipconfig /all
mac_addresses = ifconfig_output.scan(

Are there better alternatives than uuidtools nowdays?

I'm had been using uuidtools gem for years, thanks for it! ๐Ÿ‘

Because the last commit is from Aug 11, 2015, I'm thinking of using another UUID generator,
Are there better alternatives nowadays? In your opinion whats the best UUID generator in ruby (as 2017)?

Can't use uuidtools

I installed uuidtools in Windows 7 x64 with the command:

jruby -S gem install uuidtools

have written a helper:

require 'rubygems'
require 'uuidtools'

module UUIDHelper
  def self.parse(uuidstring)
    self.uuid = UUID.parse(uuidstring)
  end
  def before_create()
    self.uuid = UUID.timestamp_create().to_s
  end
end

but can't get the application to work.
The error message is:

no such file to load -- uuidtools

I searched web pages, tried all possible advices, restarted my Webrick 20 times - still no result.
By clicking "Go to declaration" on timestamp_create, NetBeans opens uuidtools.rb - so it CAN find uuidtools.
What could be wrong?

irb(main):001:0> require 'uuidtools'
LoadError: no such file to load -- uuidtools
        from org/jruby/RubyKernel.java:1038:in 'require'
        from (irb):1:in 'evaluate'
        from org/jruby/RubyKernel.java:1088:in 'eval'
        from C:/Program Files/jruby-1.6.4/lib/ruby/1.8/irb.rb:158:in 'eval_input'
        from C:/Program Files/jruby-1.6.4/lib/ruby/1.8/irb.rb:271:in 'signal_status'
        from C:/Program Files/jruby-1.6.4/lib/ruby/1.8/irb.rb:155:in 'eval_input'
        from org/jruby/RubyKernel.java:1419:in 'loop'
        from org/jruby/RubyKernel.java:1191:in 'catch'
        from C:/Program Files/jruby-1.6.4/lib/ruby/1.8/irb.rb:154:in 'eval_input'
        from C:/Program Files/jruby-1.6.4/lib/ruby/1.8/irb.rb:71:in 'start'
        from org/jruby/RubyKernel.java:1191:in 'catch'
        from C:/Program Files/jruby-1.6.4/lib/ruby/1.8/irb.rb:70:in 'start'
        from C:\Program Files\jruby-1.6.4\bin\irb:13:in '(root)'

Process Monitor shows me for "require" command:

Operation: CreateFile
Result: PATH NOT FOUND
Path:   C:\Program Files\jruby-1.6.4\lib\ruby\gems\1.8\gems\uuidtools-2.1.2\rubyjit\debug?_69049681550F92840CD2088A74CA3191A61CC9CA.class
TID:    160
Desired Access: Read Attributes
Disposition:    Open
Options:    Open Reparse Point
Attributes: n/a
ShareMode:  Read, Write, Delete
AllocationSize: n/a

P.S. It seems to be a general problem with JRuby. Other modules behave in such manner too - they can't be loaded from an application, but from irb they are loaded without problems.

Issue with timestamp_create method.

Hey,

I am receiving the following error on Jessie os using the timestamp_create method.

[1] pry(main)> UUIDTools::UUID.timestamp_create
Usage: ip [ OPTIONS ] OBJECT { COMMAND | help }
       ip [ -force ] -batch filename
where  OBJECT := { link | addr | addrlabel | route | rule | neigh | ntable |
                   tunnel | tuntap | maddr | mroute | mrule | monitor | xfrm |
                   netns | l2tp | tcp_metrics | token | netconf }
       OPTIONS := { -V[ersion] | -s[tatistics] | -d[etails] | -r[esolve] |
                    -f[amily] { inet | inet6 | ipx | dnet | bridge | link } |
                    -4 | -6 | -I | -D | -B | -0 |
                    -l[oops] { maximum-addr-flush-attempts } |
                    -o[neline] | -t[imestamp] | -b[atch] [filename] |
                    -rc[vbuf] [size]}
NoMethodError: undefined method `split' for nil:NilClass
from /usr/local/bundle/gems/uuidtools-2.1.4/lib/uuidtools.rb:611:in `first_mac'

I have looked into it in a bit of detail, Jessie uses ip instead of ifconfig and the code for the gem does the following:

all_switch = all == nil ? "" : "-a"

The "-a" options seem to be incorrect options for ip service. Should be 'device a'

root@651fc07a3a3a:r# ip -a
Option "-a" is unknown, try "ip -help".

error when running as a windows service

when running as a windows service i got this error:

uninitialized class variable @@mac_address in UUIDTools::UUID
C:/Ruby/lib/ruby/gems/1.9.1/gems/uuidtools-2.1.2/lib/uuidtools.rb:590:in `mac_address'

if the same code runs inside cmd.exe it works without any problem.

my code is:

uuid = UUIDTools::UUID.mac_address.to_s

thank you.

Testsuite fails with Ruby 1.9

ArgumentError in 'UUIDTools::UUID when parsing should correctly parse integers'
invalid byte sequence in US-ASCII
/var/tmp/portage/dev-ruby/uuidtools-2.1.0/work/uuidtools-2.1.0/spec/uuidtools/uuid_parsing_spec.rb:115:in block (2 levels) in <top (required)>' /usr/lib64/ruby19/1.9.1/timeout.rb:44:intimeout'

ArgumentError in 'UUIDTools::UUID when parsing should correctly parse hexdigests'
invalid byte sequence in US-ASCII
/var/tmp/portage/dev-ruby/uuidtools-2.1.0/work/uuidtools-2.1.0/spec/uuidtools/uuid_parsing_spec.rb:125:in block (2 levels) in <top (required)>' /usr/lib64/ruby19/1.9.1/timeout.rb:44:intimeout'

Finished in 0.323076154 seconds

41 examples, 2 failures
rake aborted!
Command /usr/bin/ruby19 -I"lib" "/usr/lib64/ruby19/gems/1.9.1/gems/rspec-1.2.9/bin/spec" "spec/uuidtools/uuid_parsing_spec.rb" "spec/uuidtools/mac_address_spec.rb" "spec/uuidtools/utility_spec.rb" "spec/uuidtools/uuid_creation_spec.rb" --color --format specdoc failed

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.