mack-data_mapper 0.8.1 → 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/gems/addressable-2.0.0/lib/addressable/idna.rb +4867 -0
- data/lib/gems/addressable-2.0.0/lib/addressable/uri.rb +2469 -0
- data/lib/gems/addressable-2.0.0/lib/addressable/version.rb +35 -0
- data/lib/gems/dm-aggregates-0.9.7/lib/dm-aggregates/adapters/data_objects_adapter.rb +85 -0
- data/lib/gems/dm-aggregates-0.9.7/lib/dm-aggregates/aggregate_functions.rb +201 -0
- data/lib/gems/dm-aggregates-0.9.7/lib/dm-aggregates/collection.rb +11 -0
- data/lib/gems/dm-aggregates-0.9.7/lib/dm-aggregates/model.rb +11 -0
- data/lib/gems/dm-aggregates-0.9.7/lib/dm-aggregates/repository.rb +7 -0
- data/lib/gems/dm-aggregates-0.9.7/lib/dm-aggregates/support/symbol.rb +21 -0
- data/lib/gems/dm-aggregates-0.9.7/lib/dm-aggregates/version.rb +7 -0
- data/lib/gems/dm-aggregates-0.9.7/lib/dm-aggregates.rb +15 -0
- data/lib/gems/dm-core-0.9.7/lib/dm-core/adapters/abstract_adapter.rb +209 -0
- data/lib/gems/dm-core-0.9.7/lib/dm-core/adapters/data_objects_adapter.rb +709 -0
- data/lib/gems/dm-core-0.9.7/lib/dm-core/adapters/in_memory_adapter.rb +87 -0
- data/lib/gems/dm-core-0.9.7/lib/dm-core/adapters/mysql_adapter.rb +136 -0
- data/lib/gems/dm-core-0.9.7/lib/dm-core/adapters/postgres_adapter.rb +188 -0
- data/lib/gems/dm-core-0.9.7/lib/dm-core/adapters/sqlite3_adapter.rb +105 -0
- data/lib/gems/dm-core-0.9.7/lib/dm-core/adapters.rb +22 -0
- data/lib/gems/dm-core-0.9.7/lib/dm-core/associations/many_to_many.rb +147 -0
- data/lib/gems/dm-core-0.9.7/lib/dm-core/associations/many_to_one.rb +107 -0
- data/lib/gems/dm-core-0.9.7/lib/dm-core/associations/one_to_many.rb +318 -0
- data/lib/gems/dm-core-0.9.7/lib/dm-core/associations/one_to_one.rb +61 -0
- data/lib/gems/dm-core-0.9.7/lib/dm-core/associations/relationship.rb +223 -0
- data/lib/gems/dm-core-0.9.7/lib/dm-core/associations/relationship_chain.rb +81 -0
- data/lib/gems/dm-core-0.9.7/lib/dm-core/associations.rb +200 -0
- data/lib/gems/dm-core-0.9.7/lib/dm-core/auto_migrations.rb +105 -0
- data/lib/gems/dm-core-0.9.7/lib/dm-core/collection.rb +642 -0
- data/lib/gems/dm-core-0.9.7/lib/dm-core/dependency_queue.rb +32 -0
- data/lib/gems/dm-core-0.9.7/lib/dm-core/hook.rb +11 -0
- data/lib/gems/dm-core-0.9.7/lib/dm-core/identity_map.rb +42 -0
- data/lib/gems/dm-core-0.9.7/lib/dm-core/is.rb +16 -0
- data/lib/gems/dm-core-0.9.7/lib/dm-core/logger.rb +232 -0
- data/lib/gems/dm-core-0.9.7/lib/dm-core/migrations/destructive_migrations.rb +17 -0
- data/lib/gems/dm-core-0.9.7/lib/dm-core/migrator.rb +29 -0
- data/lib/gems/dm-core-0.9.7/lib/dm-core/model.rb +488 -0
- data/lib/gems/dm-core-0.9.7/lib/dm-core/naming_conventions.rb +84 -0
- data/lib/gems/dm-core-0.9.7/lib/dm-core/property.rb +663 -0
- data/lib/gems/dm-core-0.9.7/lib/dm-core/property_set.rb +169 -0
- data/lib/gems/dm-core-0.9.7/lib/dm-core/query.rb +628 -0
- data/lib/gems/dm-core-0.9.7/lib/dm-core/repository.rb +159 -0
- data/lib/gems/dm-core-0.9.7/lib/dm-core/resource.rb +637 -0
- data/lib/gems/dm-core-0.9.7/lib/dm-core/scope.rb +58 -0
- data/lib/gems/dm-core-0.9.7/lib/dm-core/support/array.rb +13 -0
- data/lib/gems/dm-core-0.9.7/lib/dm-core/support/assertions.rb +8 -0
- data/lib/gems/dm-core-0.9.7/lib/dm-core/support/errors.rb +23 -0
- data/lib/gems/dm-core-0.9.7/lib/dm-core/support/kernel.rb +11 -0
- data/lib/gems/dm-core-0.9.7/lib/dm-core/support/symbol.rb +41 -0
- data/lib/gems/dm-core-0.9.7/lib/dm-core/support.rb +7 -0
- data/lib/gems/dm-core-0.9.7/lib/dm-core/transaction.rb +267 -0
- data/lib/gems/dm-core-0.9.7/lib/dm-core/type.rb +160 -0
- data/lib/gems/dm-core-0.9.7/lib/dm-core/type_map.rb +80 -0
- data/lib/gems/dm-core-0.9.7/lib/dm-core/types/boolean.rb +7 -0
- data/lib/gems/dm-core-0.9.7/lib/dm-core/types/discriminator.rb +34 -0
- data/lib/gems/dm-core-0.9.7/lib/dm-core/types/object.rb +24 -0
- data/lib/gems/dm-core-0.9.7/lib/dm-core/types/paranoid_boolean.rb +34 -0
- data/lib/gems/dm-core-0.9.7/lib/dm-core/types/paranoid_datetime.rb +33 -0
- data/lib/gems/dm-core-0.9.7/lib/dm-core/types/serial.rb +9 -0
- data/lib/gems/dm-core-0.9.7/lib/dm-core/types/text.rb +10 -0
- data/lib/gems/dm-core-0.9.7/lib/dm-core/types.rb +19 -0
- data/lib/gems/dm-core-0.9.7/lib/dm-core/version.rb +3 -0
- data/lib/gems/dm-core-0.9.7/lib/dm-core.rb +217 -0
- data/lib/gems/dm-core-0.9.7/script/all +5 -0
- data/lib/gems/dm-core-0.9.7/script/performance.rb +284 -0
- data/lib/gems/dm-core-0.9.7/script/profile.rb +87 -0
- data/lib/gems/dm-migrations-0.9.7/lib/dm-migrations/version.rb +5 -0
- data/lib/gems/dm-migrations-0.9.7/lib/dm-migrations.rb +1 -0
- data/lib/gems/dm-migrations-0.9.7/lib/migration.rb +215 -0
- data/lib/gems/dm-migrations-0.9.7/lib/migration_runner.rb +88 -0
- data/lib/gems/dm-migrations-0.9.7/lib/spec/example/migration_example_group.rb +73 -0
- data/lib/gems/dm-migrations-0.9.7/lib/spec/matchers/migration_matchers.rb +107 -0
- data/lib/gems/dm-migrations-0.9.7/lib/sql/column.rb +9 -0
- data/lib/gems/dm-migrations-0.9.7/lib/sql/mysql.rb +52 -0
- data/lib/gems/dm-migrations-0.9.7/lib/sql/postgresql.rb +78 -0
- data/lib/gems/dm-migrations-0.9.7/lib/sql/sqlite3.rb +43 -0
- data/lib/gems/dm-migrations-0.9.7/lib/sql/table.rb +19 -0
- data/lib/gems/dm-migrations-0.9.7/lib/sql/table_creator.rb +81 -0
- data/lib/gems/dm-migrations-0.9.7/lib/sql/table_modifier.rb +53 -0
- data/lib/gems/dm-migrations-0.9.7/lib/sql.rb +10 -0
- data/lib/gems/dm-observer-0.9.7/lib/dm-observer/version.rb +5 -0
- data/lib/gems/dm-observer-0.9.7/lib/dm-observer.rb +91 -0
- data/lib/gems/dm-serializer-0.9.7/lib/dm-serializer/version.rb +5 -0
- data/lib/gems/dm-serializer-0.9.7/lib/dm-serializer.rb +183 -0
- data/lib/gems/dm-timestamps-0.9.7/lib/dm-timestamps/version.rb +5 -0
- data/lib/gems/dm-timestamps-0.9.7/lib/dm-timestamps.rb +57 -0
- data/lib/gems/dm-types-0.9.7/lib/dm-types/bcrypt_hash.rb +31 -0
- data/lib/gems/dm-types-0.9.7/lib/dm-types/csv.rb +28 -0
- data/lib/gems/dm-types-0.9.7/lib/dm-types/enum.rb +70 -0
- data/lib/gems/dm-types-0.9.7/lib/dm-types/epoch_time.rb +27 -0
- data/lib/gems/dm-types-0.9.7/lib/dm-types/file_path.rb +27 -0
- data/lib/gems/dm-types-0.9.7/lib/dm-types/flag.rb +61 -0
- data/lib/gems/dm-types-0.9.7/lib/dm-types/ip_address.rb +30 -0
- data/lib/gems/dm-types-0.9.7/lib/dm-types/json.rb +40 -0
- data/lib/gems/dm-types-0.9.7/lib/dm-types/regexp.rb +20 -0
- data/lib/gems/dm-types-0.9.7/lib/dm-types/serial.rb +8 -0
- data/lib/gems/dm-types-0.9.7/lib/dm-types/slug.rb +37 -0
- data/lib/gems/dm-types-0.9.7/lib/dm-types/uri.rb +29 -0
- data/lib/gems/dm-types-0.9.7/lib/dm-types/uuid.rb +64 -0
- data/lib/gems/dm-types-0.9.7/lib/dm-types/version.rb +5 -0
- data/lib/gems/dm-types-0.9.7/lib/dm-types/yaml.rb +36 -0
- data/lib/gems/dm-types-0.9.7/lib/dm-types.rb +28 -0
- data/lib/gems/dm-validations-0.9.7/lib/dm-validations/absent_field_validator.rb +60 -0
- data/lib/gems/dm-validations-0.9.7/lib/dm-validations/acceptance_validator.rb +76 -0
- data/lib/gems/dm-validations-0.9.7/lib/dm-validations/auto_validate.rb +153 -0
- data/lib/gems/dm-validations-0.9.7/lib/dm-validations/block_validator.rb +60 -0
- data/lib/gems/dm-validations-0.9.7/lib/dm-validations/confirmation_validator.rb +80 -0
- data/lib/gems/dm-validations-0.9.7/lib/dm-validations/contextual_validators.rb +56 -0
- data/lib/gems/dm-validations-0.9.7/lib/dm-validations/custom_validator.rb +72 -0
- data/lib/gems/dm-validations-0.9.7/lib/dm-validations/format_validator.rb +97 -0
- data/lib/gems/dm-validations-0.9.7/lib/dm-validations/formats/email.rb +40 -0
- data/lib/gems/dm-validations-0.9.7/lib/dm-validations/formats/url.rb +20 -0
- data/lib/gems/dm-validations-0.9.7/lib/dm-validations/generic_validator.rb +100 -0
- data/lib/gems/dm-validations-0.9.7/lib/dm-validations/length_validator.rb +113 -0
- data/lib/gems/dm-validations-0.9.7/lib/dm-validations/method_validator.rb +68 -0
- data/lib/gems/dm-validations-0.9.7/lib/dm-validations/numeric_validator.rb +83 -0
- data/lib/gems/dm-validations-0.9.7/lib/dm-validations/primitive_validator.rb +60 -0
- data/lib/gems/dm-validations-0.9.7/lib/dm-validations/required_field_validator.rb +88 -0
- data/lib/gems/dm-validations-0.9.7/lib/dm-validations/support/object.rb +5 -0
- data/lib/gems/dm-validations-0.9.7/lib/dm-validations/uniqueness_validator.rb +64 -0
- data/lib/gems/dm-validations-0.9.7/lib/dm-validations/validation_errors.rb +63 -0
- data/lib/gems/dm-validations-0.9.7/lib/dm-validations/version.rb +5 -0
- data/lib/gems/dm-validations-0.9.7/lib/dm-validations/within_validator.rb +53 -0
- data/lib/gems/dm-validations-0.9.7/lib/dm-validations.rb +234 -0
- data/lib/gems/json_pure-1.1.3/GPL +340 -0
- data/lib/gems/json_pure-1.1.3/VERSION +1 -0
- data/lib/gems/json_pure-1.1.3/bin/edit_json.rb +10 -0
- data/lib/gems/json_pure-1.1.3/bin/prettify_json.rb +76 -0
- data/lib/gems/json_pure-1.1.3/lib/json/Array.xpm +21 -0
- data/lib/gems/json_pure-1.1.3/lib/json/FalseClass.xpm +21 -0
- data/lib/gems/json_pure-1.1.3/lib/json/Hash.xpm +21 -0
- data/lib/gems/json_pure-1.1.3/lib/json/Key.xpm +73 -0
- data/lib/gems/json_pure-1.1.3/lib/json/NilClass.xpm +21 -0
- data/lib/gems/json_pure-1.1.3/lib/json/Numeric.xpm +28 -0
- data/lib/gems/json_pure-1.1.3/lib/json/String.xpm +96 -0
- data/lib/gems/json_pure-1.1.3/lib/json/TrueClass.xpm +21 -0
- data/lib/gems/json_pure-1.1.3/lib/json/add/core.rb +135 -0
- data/lib/gems/json_pure-1.1.3/lib/json/add/rails.rb +58 -0
- data/lib/gems/json_pure-1.1.3/lib/json/common.rb +354 -0
- data/lib/gems/json_pure-1.1.3/lib/json/editor.rb +1362 -0
- data/lib/gems/json_pure-1.1.3/lib/json/ext.rb +13 -0
- data/lib/gems/json_pure-1.1.3/lib/json/json.xpm +1499 -0
- data/lib/gems/json_pure-1.1.3/lib/json/pure/generator.rb +394 -0
- data/lib/gems/json_pure-1.1.3/lib/json/pure/parser.rb +259 -0
- data/lib/gems/json_pure-1.1.3/lib/json/pure.rb +75 -0
- data/lib/gems/json_pure-1.1.3/lib/json/version.rb +9 -0
- data/lib/gems/json_pure-1.1.3/lib/json.rb +235 -0
- data/lib/gems/launchy-0.3.2/bin/launchy +12 -0
- data/lib/gems/launchy-0.3.2/lib/launchy/application.rb +163 -0
- data/lib/gems/launchy-0.3.2/lib/launchy/browser.rb +85 -0
- data/lib/gems/launchy-0.3.2/lib/launchy/command_line.rb +48 -0
- data/lib/gems/launchy-0.3.2/lib/launchy/gemspec.rb +53 -0
- data/lib/gems/launchy-0.3.2/lib/launchy/specification.rb +133 -0
- data/lib/gems/launchy-0.3.2/lib/launchy/version.rb +18 -0
- data/lib/gems/launchy-0.3.2/lib/launchy.rb +58 -0
- data/lib/gems/uuidtools-1.0.3/lib/uuidtools/version.rb +32 -0
- data/lib/gems/uuidtools-1.0.3/lib/uuidtools.rb +648 -0
- data/lib/gems.rb +13 -0
- data/lib/mack-data_mapper/migration_generator/migration_generator.rb +5 -0
- data/lib/mack-data_mapper/migration_generator/templates/db/migrations/%=@migration_name%.rb.template +1 -1
- data/lib/mack-data_mapper/model_generator/manifest.yml +3 -3
- data/lib/mack-data_mapper/model_generator/model_generator.rb +8 -1
- data/lib/mack-data_mapper/model_generator/templates/model.rb.template +1 -1
- data/lib/mack-data_mapper/model_generator/templates/rspec.rb.template +1 -1
- data/lib/mack-data_mapper/model_generator/templates/test_case.rb.template +1 -1
- data/lib/mack-data_mapper.rb +3 -2
- data/lib/mack-data_mapper_tasks.rb +7 -0
- metadata +235 -86
@@ -0,0 +1,648 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2005-2008 Robert Aman
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
#++
|
23
|
+
|
24
|
+
$:.unshift(File.dirname(__FILE__))
|
25
|
+
|
26
|
+
require 'uri'
|
27
|
+
require 'time'
|
28
|
+
require 'thread'
|
29
|
+
require 'digest/sha1'
|
30
|
+
require 'digest/md5'
|
31
|
+
|
32
|
+
require 'uuidtools/version'
|
33
|
+
|
34
|
+
# Backwards compatibility with old method of versioning.
|
35
|
+
UUID_TOOLS_VERSION = UUID::UUID_TOOLS_VERSION::STRING
|
36
|
+
|
37
|
+
# Because it's impossible to hype a UUID generator on its genuine merits,
|
38
|
+
# I give you... Really bad ASCII art in the comments:
|
39
|
+
#
|
40
|
+
#
|
41
|
+
# \
|
42
|
+
# /
|
43
|
+
# +
|
44
|
+
# ]
|
45
|
+
# ]
|
46
|
+
# |
|
47
|
+
# /
|
48
|
+
# Mp___
|
49
|
+
# `~0NNp,
|
50
|
+
# __ggM'
|
51
|
+
# g0M~"`
|
52
|
+
# ]0M*-
|
53
|
+
#
|
54
|
+
# ___
|
55
|
+
# _g000M00g,
|
56
|
+
# j0M~ ~M&
|
57
|
+
# j0M" ~N,
|
58
|
+
# j0P M&
|
59
|
+
# jM 1
|
60
|
+
# j0 ]1
|
61
|
+
# .0P 0,
|
62
|
+
# 00' M&
|
63
|
+
# 0M ]0L
|
64
|
+
# ]0f ___ M0
|
65
|
+
# M0NN0M00MMM~"'M 0&
|
66
|
+
# `~ ~0 ]0,
|
67
|
+
# ]M ]0&
|
68
|
+
# M& M0,
|
69
|
+
# ____gp_ M& M0_
|
70
|
+
# __p0MPM8MM&_ M/ ^0&_
|
71
|
+
# gN"` M0N_j0, MM&__
|
72
|
+
# _gF `~M0P` __ M00g
|
73
|
+
# g0' gM0&, ~M0&
|
74
|
+
# _pM` 0, ]M1 "00&
|
75
|
+
# _00 /g1MMgj01 ]0MI
|
76
|
+
# _0F t"M,7MMM 00I
|
77
|
+
# g0' _ N&j& 40'
|
78
|
+
# g0' _p0Mq_ ' N0QQNM#g,
|
79
|
+
# 0' _g0000000g__ ~M@MMM000g
|
80
|
+
# f _jM00@` ~M0000Mgppg, "P00&
|
81
|
+
# | g000~ `~M000000&_ ~0&
|
82
|
+
# ]M _M00F "00MM` ~#&
|
83
|
+
# `0L m000F #E "0f
|
84
|
+
# 9r j000M` 40, 00
|
85
|
+
# ]0g_ j00M` ^M0MNggp#gqpg M0&
|
86
|
+
# ~MPM0f ~M000000000g_ ,_ygg&M00f
|
87
|
+
# `~~~M00000000000000
|
88
|
+
# `M0000000000f
|
89
|
+
# ~@@@MF~`
|
90
|
+
#
|
91
|
+
#
|
92
|
+
|
93
|
+
#= uuidtools.rb
|
94
|
+
#
|
95
|
+
# UUIDTools was designed to be a simple library for generating any
|
96
|
+
# of the various types of UUIDs. It conforms to RFC 4122 whenever
|
97
|
+
# possible.
|
98
|
+
#
|
99
|
+
#== Example
|
100
|
+
# UUID.md5_create(UUID_DNS_NAMESPACE, "www.widgets.com")
|
101
|
+
# => #<UUID:0x287576 UUID:3d813cbb-47fb-32ba-91df-831e1593ac29>
|
102
|
+
# UUID.sha1_create(UUID_DNS_NAMESPACE, "www.widgets.com")
|
103
|
+
# => #<UUID:0x2a0116 UUID:21f7f8de-8051-5b89-8680-0195ef798b6a>
|
104
|
+
# UUID.timestamp_create
|
105
|
+
# => #<UUID:0x2adfdc UUID:64a5189c-25b3-11da-a97b-00c04fd430c8>
|
106
|
+
# UUID.random_create
|
107
|
+
# => #<UUID:0x19013a UUID:984265dc-4200-4f02-ae70-fe4f48964159>
|
108
|
+
class UUID
|
109
|
+
@@mac_address = nil
|
110
|
+
@@last_timestamp = nil
|
111
|
+
@@last_node_id = nil
|
112
|
+
@@last_clock_sequence = nil
|
113
|
+
@@state_file = nil
|
114
|
+
@@mutex = Mutex.new
|
115
|
+
|
116
|
+
def initialize(time_low, time_mid, time_hi_and_version,
|
117
|
+
clock_seq_hi_and_reserved, clock_seq_low, nodes)
|
118
|
+
unless time_low >= 0 && time_low < 4294967296
|
119
|
+
raise ArgumentError,
|
120
|
+
"Expected unsigned 32-bit number for time_low, got #{time_low}."
|
121
|
+
end
|
122
|
+
unless time_mid >= 0 && time_mid < 65536
|
123
|
+
raise ArgumentError,
|
124
|
+
"Expected unsigned 16-bit number for time_mid, got #{time_mid}."
|
125
|
+
end
|
126
|
+
unless time_hi_and_version >= 0 && time_hi_and_version < 65536
|
127
|
+
raise ArgumentError,
|
128
|
+
"Expected unsigned 16-bit number for time_hi_and_version, " +
|
129
|
+
"got #{time_hi_and_version}."
|
130
|
+
end
|
131
|
+
unless clock_seq_hi_and_reserved >= 0 && clock_seq_hi_and_reserved < 256
|
132
|
+
raise ArgumentError,
|
133
|
+
"Expected unsigned 8-bit number for clock_seq_hi_and_reserved, " +
|
134
|
+
"got #{clock_seq_hi_and_reserved}."
|
135
|
+
end
|
136
|
+
unless clock_seq_low >= 0 && clock_seq_low < 256
|
137
|
+
raise ArgumentError,
|
138
|
+
"Expected unsigned 8-bit number for clock_seq_low, " +
|
139
|
+
"got #{clock_seq_low}."
|
140
|
+
end
|
141
|
+
unless nodes.respond_to? :size
|
142
|
+
raise ArgumentError,
|
143
|
+
"Expected nodes to respond to :size."
|
144
|
+
end
|
145
|
+
unless nodes.size == 6
|
146
|
+
raise ArgumentError,
|
147
|
+
"Expected nodes to have size of 6."
|
148
|
+
end
|
149
|
+
for node in nodes
|
150
|
+
unless node >= 0 && node < 256
|
151
|
+
raise ArgumentError,
|
152
|
+
"Expected unsigned 8-bit number for each node, " +
|
153
|
+
"got #{node}."
|
154
|
+
end
|
155
|
+
end
|
156
|
+
@time_low = time_low
|
157
|
+
@time_mid = time_mid
|
158
|
+
@time_hi_and_version = time_hi_and_version
|
159
|
+
@clock_seq_hi_and_reserved = clock_seq_hi_and_reserved
|
160
|
+
@clock_seq_low = clock_seq_low
|
161
|
+
@nodes = nodes
|
162
|
+
end
|
163
|
+
|
164
|
+
attr_accessor :time_low
|
165
|
+
attr_accessor :time_mid
|
166
|
+
attr_accessor :time_hi_and_version
|
167
|
+
attr_accessor :clock_seq_hi_and_reserved
|
168
|
+
attr_accessor :clock_seq_low
|
169
|
+
attr_accessor :nodes
|
170
|
+
|
171
|
+
# Parses a UUID from a string.
|
172
|
+
def self.parse(uuid_string)
|
173
|
+
unless uuid_string.kind_of? String
|
174
|
+
raise ArgumentError,
|
175
|
+
"Expected String, got #{uuid_string.class.name} instead."
|
176
|
+
end
|
177
|
+
uuid_components = uuid_string.downcase.scan(
|
178
|
+
Regexp.new("^([0-9a-f]{8})-([0-9a-f]{4})-([0-9a-f]{4})-" +
|
179
|
+
"([0-9a-f]{2})([0-9a-f]{2})-([0-9a-f]{12})$")).first
|
180
|
+
raise ArgumentError, "Invalid UUID format." if uuid_components.nil?
|
181
|
+
time_low = uuid_components[0].to_i(16)
|
182
|
+
time_mid = uuid_components[1].to_i(16)
|
183
|
+
time_hi_and_version = uuid_components[2].to_i(16)
|
184
|
+
clock_seq_hi_and_reserved = uuid_components[3].to_i(16)
|
185
|
+
clock_seq_low = uuid_components[4].to_i(16)
|
186
|
+
nodes = []
|
187
|
+
for i in 0..5
|
188
|
+
nodes << uuid_components[5][(i * 2)..(i * 2) + 1].to_i(16)
|
189
|
+
end
|
190
|
+
return self.new(time_low, time_mid, time_hi_and_version,
|
191
|
+
clock_seq_hi_and_reserved, clock_seq_low, nodes)
|
192
|
+
end
|
193
|
+
|
194
|
+
# Parses a UUID from a raw byte string.
|
195
|
+
def self.parse_raw(raw_string)
|
196
|
+
unless raw_string.kind_of? String
|
197
|
+
raise ArgumentError,
|
198
|
+
"Expected String, got #{raw_string.class.name} instead."
|
199
|
+
end
|
200
|
+
integer = self.convert_byte_string_to_int(raw_string)
|
201
|
+
|
202
|
+
time_low = (integer >> 96) & 0xFFFFFFFF
|
203
|
+
time_mid = (integer >> 80) & 0xFFFF
|
204
|
+
time_hi_and_version = (integer >> 64) & 0xFFFF
|
205
|
+
clock_seq_hi_and_reserved = (integer >> 56) & 0xFF
|
206
|
+
clock_seq_low = (integer >> 48) & 0xFF
|
207
|
+
nodes = []
|
208
|
+
for i in 0..5
|
209
|
+
nodes << ((integer >> (40 - (i * 8))) & 0xFF)
|
210
|
+
end
|
211
|
+
return self.new(time_low, time_mid, time_hi_and_version,
|
212
|
+
clock_seq_hi_and_reserved, clock_seq_low, nodes)
|
213
|
+
end
|
214
|
+
|
215
|
+
# Creates a UUID from a random value.
|
216
|
+
def self.random_create()
|
217
|
+
new_uuid = self.parse_raw(self.random_128)
|
218
|
+
new_uuid.time_hi_and_version &= 0x0FFF
|
219
|
+
new_uuid.time_hi_and_version |= (4 << 12)
|
220
|
+
new_uuid.clock_seq_hi_and_reserved &= 0x3F
|
221
|
+
new_uuid.clock_seq_hi_and_reserved |= 0x80
|
222
|
+
return new_uuid
|
223
|
+
end
|
224
|
+
|
225
|
+
# Creates a UUID from a timestamp.
|
226
|
+
def self.timestamp_create(timestamp=nil)
|
227
|
+
# We need a lock here to prevent two threads from ever
|
228
|
+
# getting the same timestamp.
|
229
|
+
@@mutex.synchronize do
|
230
|
+
# Always use GMT to generate UUIDs.
|
231
|
+
if timestamp.nil?
|
232
|
+
gmt_timestamp = Time.now.gmtime
|
233
|
+
else
|
234
|
+
gmt_timestamp = timestamp.gmtime
|
235
|
+
end
|
236
|
+
# Convert to 100 nanosecond blocks
|
237
|
+
gmt_timestamp_100_nanoseconds = (gmt_timestamp.tv_sec * 10000000) +
|
238
|
+
(gmt_timestamp.tv_usec * 10) + 0x01B21DD213814000
|
239
|
+
mac_address = self.get_mac_address
|
240
|
+
if mac_address == nil || mac_address == ""
|
241
|
+
raise StandardError,
|
242
|
+
"MAC address could not be autodetected. " +
|
243
|
+
"Set the MAC address manually."
|
244
|
+
end
|
245
|
+
nodes = mac_address.split(":").collect do |octet|
|
246
|
+
octet.to_i(16)
|
247
|
+
end
|
248
|
+
node_id = 0
|
249
|
+
for i in 0..5
|
250
|
+
node_id += (nodes[i] << (40 - (i * 8)))
|
251
|
+
end
|
252
|
+
clock_sequence = @@last_clock_sequence
|
253
|
+
if clock_sequence.nil?
|
254
|
+
clock_sequence = self.convert_byte_string_to_int(self.random_128)
|
255
|
+
end
|
256
|
+
if @@last_node_id != nil && @@last_node_id != node_id
|
257
|
+
# The node id has changed. Change the clock id.
|
258
|
+
clock_sequence = self.convert_byte_string_to_int(self.random_128)
|
259
|
+
elsif @@last_timestamp != nil &&
|
260
|
+
gmt_timestamp_100_nanoseconds <= @@last_timestamp
|
261
|
+
clock_sequence = clock_sequence + 1
|
262
|
+
end
|
263
|
+
@@last_timestamp = gmt_timestamp_100_nanoseconds
|
264
|
+
@@last_node_id = node_id
|
265
|
+
@@last_clock_sequence = clock_sequence
|
266
|
+
|
267
|
+
time_low = gmt_timestamp_100_nanoseconds & 0xFFFFFFFF
|
268
|
+
time_mid = ((gmt_timestamp_100_nanoseconds >> 32) & 0xFFFF)
|
269
|
+
time_hi_and_version = ((gmt_timestamp_100_nanoseconds >> 48) & 0x0FFF)
|
270
|
+
time_hi_and_version |= (1 << 12)
|
271
|
+
clock_seq_low = clock_sequence & 0xFF;
|
272
|
+
clock_seq_hi_and_reserved = (clock_sequence & 0x3F00) >> 8
|
273
|
+
clock_seq_hi_and_reserved |= 0x80
|
274
|
+
|
275
|
+
return self.new(time_low, time_mid, time_hi_and_version,
|
276
|
+
clock_seq_hi_and_reserved, clock_seq_low, nodes)
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
280
|
+
# Creates a UUID using the MD5 hash. (Version 3)
|
281
|
+
def self.md5_create(namespace, name)
|
282
|
+
return self.create_from_hash(Digest::MD5, namespace, name)
|
283
|
+
end
|
284
|
+
|
285
|
+
# Creates a UUID using the SHA1 hash. (Version 5)
|
286
|
+
def self.sha1_create(namespace, name)
|
287
|
+
return self.create_from_hash(Digest::SHA1, namespace, name)
|
288
|
+
end
|
289
|
+
|
290
|
+
# This method applies only to version 1 UUIDs.
|
291
|
+
# Checks if the node ID was generated from a random number
|
292
|
+
# or from an IEEE 802 address (MAC address).
|
293
|
+
# Always returns false for UUIDs that aren't version 1.
|
294
|
+
# This should not be confused with version 4 UUIDs where
|
295
|
+
# more than just the node id is random.
|
296
|
+
def random_node_id?
|
297
|
+
return false if self.version != 1
|
298
|
+
return ((self.nodes.first & 0x01) == 1)
|
299
|
+
end
|
300
|
+
|
301
|
+
# Returns true if this UUID is the
|
302
|
+
# nil UUID (00000000-0000-0000-0000-000000000000).
|
303
|
+
def nil_uuid?
|
304
|
+
return false if self.time_low != 0
|
305
|
+
return false if self.time_mid != 0
|
306
|
+
return false if self.time_hi_and_version != 0
|
307
|
+
return false if self.clock_seq_hi_and_reserved != 0
|
308
|
+
return false if self.clock_seq_low != 0
|
309
|
+
self.nodes.each do |node|
|
310
|
+
return false if node != 0
|
311
|
+
end
|
312
|
+
return true
|
313
|
+
end
|
314
|
+
|
315
|
+
# Returns the UUID version type.
|
316
|
+
# Possible values:
|
317
|
+
# 1 - Time-based with unique or random host identifier
|
318
|
+
# 2 - DCE Security version (with POSIX UIDs)
|
319
|
+
# 3 - Name-based (MD5 hash)
|
320
|
+
# 4 - Random
|
321
|
+
# 5 - Name-based (SHA-1 hash)
|
322
|
+
def version
|
323
|
+
return (time_hi_and_version >> 12)
|
324
|
+
end
|
325
|
+
|
326
|
+
# Returns the UUID variant.
|
327
|
+
# Possible values:
|
328
|
+
# 0b000 - Reserved, NCS backward compatibility.
|
329
|
+
# 0b100 - The variant specified in this document.
|
330
|
+
# 0b110 - Reserved, Microsoft Corporation backward compatibility.
|
331
|
+
# 0b111 - Reserved for future definition.
|
332
|
+
def variant
|
333
|
+
variant_raw = (clock_seq_hi_and_reserved >> 5)
|
334
|
+
result = nil
|
335
|
+
if (variant_raw >> 2) == 0
|
336
|
+
result = 0x000
|
337
|
+
elsif (variant_raw >> 1) == 2
|
338
|
+
result = 0x100
|
339
|
+
else
|
340
|
+
result = variant_raw
|
341
|
+
end
|
342
|
+
return (result >> 6)
|
343
|
+
end
|
344
|
+
|
345
|
+
# Returns true if this UUID is valid.
|
346
|
+
def valid?
|
347
|
+
if [0b000, 0b100, 0b110, 0b111].include?(self.variant) &&
|
348
|
+
(1..5).include?(self.version)
|
349
|
+
return true
|
350
|
+
else
|
351
|
+
return false
|
352
|
+
end
|
353
|
+
end
|
354
|
+
|
355
|
+
# Returns the IEEE 802 address used to generate this UUID or
|
356
|
+
# nil if a MAC address was not used.
|
357
|
+
def mac_address
|
358
|
+
return nil if self.version != 1
|
359
|
+
return nil if self.random_node_id?
|
360
|
+
return (self.nodes.collect do |node|
|
361
|
+
sprintf("%2.2x", node)
|
362
|
+
end).join(":")
|
363
|
+
end
|
364
|
+
|
365
|
+
# Returns the timestamp used to generate this UUID
|
366
|
+
def timestamp
|
367
|
+
return nil if self.version != 1
|
368
|
+
gmt_timestamp_100_nanoseconds = 0
|
369
|
+
gmt_timestamp_100_nanoseconds +=
|
370
|
+
((self.time_hi_and_version & 0x0FFF) << 48)
|
371
|
+
gmt_timestamp_100_nanoseconds += (self.time_mid << 32)
|
372
|
+
gmt_timestamp_100_nanoseconds += self.time_low
|
373
|
+
return Time.at(
|
374
|
+
(gmt_timestamp_100_nanoseconds - 0x01B21DD213814000) / 10000000.0)
|
375
|
+
end
|
376
|
+
|
377
|
+
# Compares two UUIDs lexically
|
378
|
+
def <=>(other_uuid)
|
379
|
+
check = self.time_low <=> other_uuid.time_low
|
380
|
+
return check if check != 0
|
381
|
+
check = self.time_mid <=> other_uuid.time_mid
|
382
|
+
return check if check != 0
|
383
|
+
check = self.time_hi_and_version <=> other_uuid.time_hi_and_version
|
384
|
+
return check if check != 0
|
385
|
+
check = self.clock_seq_hi_and_reserved <=>
|
386
|
+
other_uuid.clock_seq_hi_and_reserved
|
387
|
+
return check if check != 0
|
388
|
+
check = self.clock_seq_low <=> other_uuid.clock_seq_low
|
389
|
+
return check if check != 0
|
390
|
+
for i in 0..5
|
391
|
+
if (self.nodes[i] < other_uuid.nodes[i])
|
392
|
+
return -1
|
393
|
+
end
|
394
|
+
if (self.nodes[i] > other_uuid.nodes[i])
|
395
|
+
return 1
|
396
|
+
end
|
397
|
+
end
|
398
|
+
return 0
|
399
|
+
end
|
400
|
+
|
401
|
+
# Returns a representation of the object's state
|
402
|
+
def inspect
|
403
|
+
return "#<UUID:0x#{self.object_id.to_s(16)} UUID:#{self.to_s}>"
|
404
|
+
end
|
405
|
+
|
406
|
+
# Returns the hex digest of the UUID object.
|
407
|
+
def hexdigest
|
408
|
+
return self.to_i.to_s(16)
|
409
|
+
end
|
410
|
+
|
411
|
+
# Returns the raw bytes that represent this UUID.
|
412
|
+
def raw
|
413
|
+
return self.class.convert_int_to_byte_string(self.to_i, 16)
|
414
|
+
end
|
415
|
+
|
416
|
+
# Returns a string representation for this UUID.
|
417
|
+
def to_s
|
418
|
+
result = sprintf("%8.8x-%4.4x-%4.4x-%2.2x%2.2x-", @time_low, @time_mid,
|
419
|
+
@time_hi_and_version, @clock_seq_hi_and_reserved, @clock_seq_low);
|
420
|
+
for i in 0..5
|
421
|
+
result << sprintf("%2.2x", @nodes[i])
|
422
|
+
end
|
423
|
+
return result.downcase
|
424
|
+
end
|
425
|
+
|
426
|
+
# Returns an integer representation for this UUID.
|
427
|
+
def to_i
|
428
|
+
bytes = (time_low << 96) + (time_mid << 80) +
|
429
|
+
(time_hi_and_version << 64) + (clock_seq_hi_and_reserved << 56) +
|
430
|
+
(clock_seq_low << 48)
|
431
|
+
for i in 0..5
|
432
|
+
bytes += (nodes[i] << (40 - (i * 8)))
|
433
|
+
end
|
434
|
+
return bytes
|
435
|
+
end
|
436
|
+
|
437
|
+
# Returns a URI string for this UUID.
|
438
|
+
def to_uri
|
439
|
+
return "urn:uuid:#{self.to_s}"
|
440
|
+
end
|
441
|
+
|
442
|
+
# Returns an integer hash value.
|
443
|
+
def hash
|
444
|
+
return self.to_i
|
445
|
+
end
|
446
|
+
|
447
|
+
# Returns true if this UUID is exactly equal to the other UUID.
|
448
|
+
def eql?(other)
|
449
|
+
return (self <=> other) == 0
|
450
|
+
end
|
451
|
+
|
452
|
+
def self.create_from_hash(hash_class, namespace, name) #:nodoc:
|
453
|
+
if hash_class == Digest::MD5
|
454
|
+
version = 3
|
455
|
+
elsif hash_class == Digest::SHA1
|
456
|
+
version = 5
|
457
|
+
else
|
458
|
+
raise ArgumentError,
|
459
|
+
"Expected Digest::SHA1 or Digest::MD5, got #{hash_class.name}."
|
460
|
+
end
|
461
|
+
hash = hash_class.new
|
462
|
+
hash.update(namespace.raw)
|
463
|
+
hash.update(name)
|
464
|
+
hash_string = hash.to_s[0..31]
|
465
|
+
new_uuid = self.parse("#{hash_string[0..7]}-#{hash_string[8..11]}-" +
|
466
|
+
"#{hash_string[12..15]}-#{hash_string[16..19]}-#{hash_string[20..31]}")
|
467
|
+
|
468
|
+
new_uuid.time_hi_and_version &= 0x0FFF
|
469
|
+
new_uuid.time_hi_and_version |= (version << 12)
|
470
|
+
new_uuid.clock_seq_hi_and_reserved &= 0x3F
|
471
|
+
new_uuid.clock_seq_hi_and_reserved |= 0x80
|
472
|
+
return new_uuid
|
473
|
+
end
|
474
|
+
|
475
|
+
# Returns the MAC address of the current computer's network card.
|
476
|
+
# Returns nil if a MAC address could not be found.
|
477
|
+
def self.mac_address #:nodoc:
|
478
|
+
if @@mac_address.nil?
|
479
|
+
require 'rbconfig'
|
480
|
+
os_platform = Config::CONFIG['target_os']
|
481
|
+
if os_platform =~ /win/ && !(os_platform =~ /darwin/)
|
482
|
+
script_in_path = true
|
483
|
+
else
|
484
|
+
script_in_path = !(`which ifconfig`.strip =~ /no .+ in/)
|
485
|
+
end
|
486
|
+
if os_platform =~ /solaris/
|
487
|
+
begin
|
488
|
+
ifconfig_output =
|
489
|
+
(script_in_path ? `ifconfig -a` : `/sbin/ifconfig -a`)
|
490
|
+
ip_addresses = ifconfig_output.scan(
|
491
|
+
/inet\s?(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/)
|
492
|
+
ip = ip_addresses.find {|addr| addr[0] != '127.0.0.1'}[0]
|
493
|
+
@@mac_address = `/usr/sbin/arp #{ip}`.split(' ')[3]
|
494
|
+
rescue Exception
|
495
|
+
end
|
496
|
+
if @@mac_address == "" || @@mac_address == nil
|
497
|
+
begin
|
498
|
+
ifconfig_output =
|
499
|
+
(script_in_path ?
|
500
|
+
`ifconfig -a` : `/sbin/ifconfig -a`).split(' ')
|
501
|
+
index = ifconfig_output.index("inet") + 1
|
502
|
+
ip = ifconfig_output[index]
|
503
|
+
@@mac_address = `arp #{ip}`.split(' ')[3]
|
504
|
+
rescue Exception
|
505
|
+
end
|
506
|
+
end
|
507
|
+
elsif os_platform =~ /win/ && !(os_platform =~ /darwin/)
|
508
|
+
begin
|
509
|
+
ifconfig_output = `ipconfig /all`
|
510
|
+
mac_addresses = ifconfig_output.scan(
|
511
|
+
Regexp.new("(#{(["[0-9a-fA-F]{2}"] * 6).join("-")})"))
|
512
|
+
if mac_addresses.size > 0
|
513
|
+
@@mac_address = mac_addresses.first.first.downcase.gsub(/-/, ":")
|
514
|
+
end
|
515
|
+
rescue
|
516
|
+
end
|
517
|
+
else
|
518
|
+
begin
|
519
|
+
mac_addresses = []
|
520
|
+
if os_platform =~ /netbsd/
|
521
|
+
ifconfig_output =
|
522
|
+
(script_in_path ? `ifconfig -a 2>&1` : `/sbin/ifconfig -a 2>&1`)
|
523
|
+
mac_addresses = ifconfig_output.scan(
|
524
|
+
Regexp.new("address\: (#{(["[0-9a-fA-F]{2}"] * 6).join(":")})"))
|
525
|
+
elsif os_platform =~ /openbsd/
|
526
|
+
ifconfig_output = `/sbin/ifconfig -a 2>&1`
|
527
|
+
ifconfig_output =
|
528
|
+
(script_in_path ? `ifconfig -a 2>&1` : `/sbin/ifconfig -a 2>&1`)
|
529
|
+
mac_addresses = ifconfig_output.scan(
|
530
|
+
Regexp.new("addr (#{(["[0-9a-fA-F]{2}"] * 6).join(":")})"))
|
531
|
+
elsif File.exists?('/sbin/ifconfig')
|
532
|
+
ifconfig_output =
|
533
|
+
(script_in_path ? `ifconfig 2>&1` : `/sbin/ifconfig 2>&1`)
|
534
|
+
mac_addresses = ifconfig_output.scan(
|
535
|
+
Regexp.new("ether (#{(["[0-9a-fA-F]{2}"] * 6).join(":")})"))
|
536
|
+
if mac_addresses.size == 0
|
537
|
+
ifconfig_output =
|
538
|
+
(script_in_path ?
|
539
|
+
`ifconfig -a 2>&1` : `/sbin/ifconfig -a 2>&1`)
|
540
|
+
mac_addresses = ifconfig_output.scan(
|
541
|
+
Regexp.new("ether (#{(["[0-9a-fA-F]{2}"] * 6).join(":")})"))
|
542
|
+
end
|
543
|
+
if mac_addresses.size == 0
|
544
|
+
ifconfig_output =
|
545
|
+
(script_in_path ?
|
546
|
+
`ifconfig | grep HWaddr | cut -c39- 2>&1` :
|
547
|
+
`/sbin/ifconfig | grep HWaddr | cut -c39- 2>&1`)
|
548
|
+
mac_addresses = ifconfig_output.scan(
|
549
|
+
Regexp.new("(#{(["[0-9a-fA-F]{2}"] * 6).join(":")})"))
|
550
|
+
end
|
551
|
+
else
|
552
|
+
ifconfig_output =
|
553
|
+
(script_in_path ? `ifconfig 2>&1` : `/sbin/ifconfig 2>&1`)
|
554
|
+
mac_addresses = ifconfig_output.scan(
|
555
|
+
Regexp.new("ether (#{(["[0-9a-fA-F]{2}"] * 6).join(":")})"))
|
556
|
+
if mac_addresses.size == 0
|
557
|
+
ifconfig_output =
|
558
|
+
(script_in_path ?
|
559
|
+
`ifconfig -a 2>&1` : `/sbin/ifconfig -a 2>&1`)
|
560
|
+
mac_addresses = ifconfig_output.scan(
|
561
|
+
Regexp.new("ether (#{(["[0-9a-fA-F]{2}"] * 6).join(":")})"))
|
562
|
+
end
|
563
|
+
if mac_addresses.size == 0
|
564
|
+
ifconfig_output =
|
565
|
+
(script_in_path ?
|
566
|
+
`ifconfig | grep HWaddr | cut -c39- 2>&1` :
|
567
|
+
`/sbin/ifconfig | grep HWaddr | cut -c39- 2>&1`)
|
568
|
+
mac_addresses = ifconfig_output.scan(
|
569
|
+
Regexp.new("(#{(["[0-9a-fA-F]{2}"] * 6).join(":")})"))
|
570
|
+
end
|
571
|
+
end
|
572
|
+
if mac_addresses.size > 0
|
573
|
+
@@mac_address = mac_addresses.first.first
|
574
|
+
end
|
575
|
+
rescue
|
576
|
+
end
|
577
|
+
end
|
578
|
+
if @@mac_address != nil
|
579
|
+
if @@mac_address.respond_to?(:to_str)
|
580
|
+
@@mac_address = @@mac_address.to_str
|
581
|
+
else
|
582
|
+
@@mac_address = @@mac_address.to_s
|
583
|
+
end
|
584
|
+
@@mac_address.downcase!
|
585
|
+
@@mac_address.strip!
|
586
|
+
end
|
587
|
+
|
588
|
+
# Verify that the MAC address is in the right format.
|
589
|
+
# Nil it out if it isn't.
|
590
|
+
unless @@mac_address.respond_to?(:scan) &&
|
591
|
+
@@mac_address.scan(/#{(["[0-9a-f]{2}"] * 6).join(":")}/)
|
592
|
+
@@mac_address = nil
|
593
|
+
end
|
594
|
+
end
|
595
|
+
return @@mac_address
|
596
|
+
end
|
597
|
+
class <<self
|
598
|
+
alias_method :get_mac_address, :mac_address
|
599
|
+
end
|
600
|
+
|
601
|
+
# Allows users to set the MAC address manually in cases where the MAC
|
602
|
+
# address cannot be obtained programatically.
|
603
|
+
def self.mac_address=(new_mac_address)
|
604
|
+
@@mac_address = new_mac_address
|
605
|
+
end
|
606
|
+
|
607
|
+
# 128 bits of unpredictable data.
|
608
|
+
def self.random_128 #:nodoc:
|
609
|
+
if !defined?(@random_device) || @random_device == nil
|
610
|
+
begin
|
611
|
+
@random_device = nil
|
612
|
+
if File.exists? "/dev/urandom"
|
613
|
+
@random_device = File.open "/dev/urandom", "r"
|
614
|
+
elsif File.exists? "/dev/random"
|
615
|
+
@random_device = File.open "/dev/random", "r"
|
616
|
+
end
|
617
|
+
rescue Exception
|
618
|
+
end
|
619
|
+
end
|
620
|
+
begin
|
621
|
+
return @random_device.read(16) if @random_device != nil
|
622
|
+
rescue Exception
|
623
|
+
end
|
624
|
+
return (1..8).to_a.map { rand(0x10000) }.pack("n8")
|
625
|
+
end
|
626
|
+
|
627
|
+
def self.convert_int_to_byte_string(integer, size) #:nodoc:
|
628
|
+
byte_string = ""
|
629
|
+
for i in 0..(size - 1)
|
630
|
+
byte_string << ((integer >> (((size - 1) - i) * 8)) & 0xFF)
|
631
|
+
end
|
632
|
+
return byte_string
|
633
|
+
end
|
634
|
+
|
635
|
+
def self.convert_byte_string_to_int(byte_string) #:nodoc:
|
636
|
+
integer = 0
|
637
|
+
size = byte_string.size
|
638
|
+
for i in 0..(size - 1)
|
639
|
+
integer += (byte_string[i] << (((size - 1) - i) * 8))
|
640
|
+
end
|
641
|
+
return integer
|
642
|
+
end
|
643
|
+
end
|
644
|
+
|
645
|
+
UUID_DNS_NAMESPACE = UUID.parse("6ba7b810-9dad-11d1-80b4-00c04fd430c8")
|
646
|
+
UUID_URL_NAMESPACE = UUID.parse("6ba7b811-9dad-11d1-80b4-00c04fd430c8")
|
647
|
+
UUID_OID_NAMESPACE = UUID.parse("6ba7b812-9dad-11d1-80b4-00c04fd430c8")
|
648
|
+
UUID_X500_NAMESPACE = UUID.parse("6ba7b814-9dad-11d1-80b4-00c04fd430c8")
|
data/lib/gems.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
path = File.expand_path(File.join(File.dirname(__FILE__), 'gems'))
|
2
|
+
Gem.set_paths(path)
|
3
|
+
|
4
|
+
Dir.glob(File.join(path, '*')).each do |p|
|
5
|
+
full_gem_name = File.basename(p)
|
6
|
+
version = full_gem_name.match(/([\d\.?]+)/).to_s
|
7
|
+
gem_name = full_gem_name.gsub("-#{version}", '')
|
8
|
+
$:.unshift(File.join(p, 'lib'))
|
9
|
+
begin
|
10
|
+
gem gem_name, "~> #{version}"
|
11
|
+
rescue Gem::LoadError
|
12
|
+
end
|
13
|
+
end
|
@@ -36,6 +36,11 @@ class MigrationGenerator < Genosaurus
|
|
36
36
|
require_param :name
|
37
37
|
|
38
38
|
def setup # :nodoc:
|
39
|
+
@name_singular = param(:name).singular.underscore
|
40
|
+
@name_plural = @name_singular.plural.underscore
|
41
|
+
@name_singular_camel = @name_singular.camelcase
|
42
|
+
@name_plural_camel = @name_plural.camelcase
|
43
|
+
|
39
44
|
@table_name = param(:name).underscore.gsub("create_", "")
|
40
45
|
@current_migration_number = next_migration_number
|
41
46
|
@migration_name = "#{@current_migration_number}_#{param(:name).underscore}"
|
@@ -4,15 +4,15 @@ models_directory:
|
|
4
4
|
model_template:
|
5
5
|
type: file
|
6
6
|
template_path: <%= File.join(templates_directory_path, "model.rb.template") %>
|
7
|
-
output_path: <%= File.join("app", "models", "#{
|
7
|
+
output_path: <%= File.join("app", "models", "#{@name_singular}.rb") %>
|
8
8
|
<% if configatron.mack.testing_framework.to_s == "test_case" -%>
|
9
9
|
test_template:
|
10
10
|
type: file
|
11
11
|
template_path: <%= File.join(templates_directory_path, "test_case.rb.template") %>
|
12
|
-
output_path: <%= File.join("test", "models", "#{
|
12
|
+
output_path: <%= File.join("test", "models", "#{@name_singular}_test.rb") %>
|
13
13
|
<% elsif configatron.mack.testing_framework.to_s == "rspec" -%>
|
14
14
|
test_template:
|
15
15
|
type: file
|
16
16
|
template_path: <%= File.join(templates_directory_path, "rspec.rb.template") %>
|
17
|
-
output_path: <%= File.join("test", "models", "#{
|
17
|
+
output_path: <%= File.join("test", "models", "#{@name_singular}_spec.rb") %>
|
18
18
|
<% end -%>
|