mack-data_mapper 0.8.1 → 0.8.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.
- 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,75 @@
|
|
|
1
|
+
require 'json/common'
|
|
2
|
+
require 'json/pure/parser'
|
|
3
|
+
require 'json/pure/generator'
|
|
4
|
+
|
|
5
|
+
module JSON
|
|
6
|
+
begin
|
|
7
|
+
require 'iconv'
|
|
8
|
+
# An iconv instance to convert from UTF8 to UTF16 Big Endian.
|
|
9
|
+
UTF16toUTF8 = Iconv.new('utf-8', 'utf-16be') # :nodoc:
|
|
10
|
+
# An iconv instance to convert from UTF16 Big Endian to UTF8.
|
|
11
|
+
UTF8toUTF16 = Iconv.new('utf-16be', 'utf-8') # :nodoc:
|
|
12
|
+
UTF8toUTF16.iconv('no bom')
|
|
13
|
+
rescue Errno::EINVAL, Iconv::InvalidEncoding
|
|
14
|
+
# Iconv doesn't support big endian utf-16. Let's try to hack this manually
|
|
15
|
+
# into the converters.
|
|
16
|
+
begin
|
|
17
|
+
old_verbose, $VERBSOSE = $VERBOSE, nil
|
|
18
|
+
# An iconv instance to convert from UTF8 to UTF16 Big Endian.
|
|
19
|
+
UTF16toUTF8 = Iconv.new('utf-8', 'utf-16') # :nodoc:
|
|
20
|
+
# An iconv instance to convert from UTF16 Big Endian to UTF8.
|
|
21
|
+
UTF8toUTF16 = Iconv.new('utf-16', 'utf-8') # :nodoc:
|
|
22
|
+
UTF8toUTF16.iconv('no bom')
|
|
23
|
+
if UTF8toUTF16.iconv("\xe2\x82\xac") == "\xac\x20"
|
|
24
|
+
swapper = Class.new do
|
|
25
|
+
def initialize(iconv) # :nodoc:
|
|
26
|
+
@iconv = iconv
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def iconv(string) # :nodoc:
|
|
30
|
+
result = @iconv.iconv(string)
|
|
31
|
+
JSON.swap!(result)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
UTF8toUTF16 = swapper.new(UTF8toUTF16) # :nodoc:
|
|
35
|
+
end
|
|
36
|
+
if UTF16toUTF8.iconv("\xac\x20") == "\xe2\x82\xac"
|
|
37
|
+
swapper = Class.new do
|
|
38
|
+
def initialize(iconv) # :nodoc:
|
|
39
|
+
@iconv = iconv
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def iconv(string) # :nodoc:
|
|
43
|
+
string = JSON.swap!(string.dup)
|
|
44
|
+
@iconv.iconv(string)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
UTF16toUTF8 = swapper.new(UTF16toUTF8) # :nodoc:
|
|
48
|
+
end
|
|
49
|
+
rescue Errno::EINVAL, Iconv::InvalidEncoding
|
|
50
|
+
raise MissingUnicodeSupport, "iconv doesn't seem to support UTF-8/UTF-16 conversions"
|
|
51
|
+
ensure
|
|
52
|
+
$VERBOSE = old_verbose
|
|
53
|
+
end
|
|
54
|
+
rescue LoadError
|
|
55
|
+
raise MissingUnicodeSupport,
|
|
56
|
+
"iconv couldn't be loaded, which is required for UTF-8/UTF-16 conversions"
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# Swap consecutive bytes of _string_ in place.
|
|
60
|
+
def self.swap!(string) # :nodoc:
|
|
61
|
+
0.upto(string.size / 2) do |i|
|
|
62
|
+
break unless string[2 * i + 1]
|
|
63
|
+
string[2 * i], string[2 * i + 1] = string[2 * i + 1], string[2 * i]
|
|
64
|
+
end
|
|
65
|
+
string
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# This module holds all the modules/classes that implement JSON's
|
|
69
|
+
# functionality in pure ruby.
|
|
70
|
+
module Pure
|
|
71
|
+
$DEBUG and warn "Using pure library for JSON."
|
|
72
|
+
JSON.parser = Parser
|
|
73
|
+
JSON.generator = Generator
|
|
74
|
+
end
|
|
75
|
+
end
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
module JSON
|
|
2
|
+
# JSON version
|
|
3
|
+
VERSION = '1.1.3'
|
|
4
|
+
VERSION_ARRAY = VERSION.split(/\./).map { |x| x.to_i } # :nodoc:
|
|
5
|
+
VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
|
|
6
|
+
VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
|
|
7
|
+
VERSION_BUILD = VERSION_ARRAY[2] # :nodoc:
|
|
8
|
+
VARIANT_BINARY = false
|
|
9
|
+
end
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
require 'json/common'
|
|
2
|
+
# = json - JSON for Ruby
|
|
3
|
+
#
|
|
4
|
+
# == Description
|
|
5
|
+
#
|
|
6
|
+
# This is a implementation of the JSON specification according to RFC 4627
|
|
7
|
+
# (http://www.ietf.org/rfc/rfc4627.txt). Starting from version 1.0.0 on there
|
|
8
|
+
# will be two variants available:
|
|
9
|
+
#
|
|
10
|
+
# * A pure ruby variant, that relies on the iconv and the stringscan
|
|
11
|
+
# extensions, which are both part of the ruby standard library.
|
|
12
|
+
# * The quite a bit faster C extension variant, which is in parts implemented
|
|
13
|
+
# in C and comes with its own unicode conversion functions and a parser
|
|
14
|
+
# generated by the ragel state machine compiler
|
|
15
|
+
# (http://www.cs.queensu.ca/~thurston/ragel).
|
|
16
|
+
#
|
|
17
|
+
# Both variants of the JSON generator escape all non-ASCII an control
|
|
18
|
+
# characters with \uXXXX escape sequences, and support UTF-16 surrogate pairs
|
|
19
|
+
# in order to be able to generate the whole range of unicode code points. This
|
|
20
|
+
# means that generated JSON text is encoded as UTF-8 (because ASCII is a subset
|
|
21
|
+
# of UTF-8) and at the same time avoids decoding problems for receiving
|
|
22
|
+
# endpoints, that don't expect UTF-8 encoded texts. On the negative side this
|
|
23
|
+
# may lead to a bit longer strings than necessarry.
|
|
24
|
+
#
|
|
25
|
+
# All strings, that are to be encoded as JSON strings, should be UTF-8 byte
|
|
26
|
+
# sequences on the Ruby side. To encode raw binary strings, that aren't UTF-8
|
|
27
|
+
# encoded, please use the to_json_raw_object method of String (which produces
|
|
28
|
+
# an object, that contains a byte array) and decode the result on the receiving
|
|
29
|
+
# endpoint.
|
|
30
|
+
#
|
|
31
|
+
# == Author
|
|
32
|
+
#
|
|
33
|
+
# Florian Frank <mailto:flori@ping.de>
|
|
34
|
+
#
|
|
35
|
+
# == License
|
|
36
|
+
#
|
|
37
|
+
# This software is distributed under the same license as Ruby itself, see
|
|
38
|
+
# http://www.ruby-lang.org/en/LICENSE.txt.
|
|
39
|
+
#
|
|
40
|
+
# == Download
|
|
41
|
+
#
|
|
42
|
+
# The latest version of this library can be downloaded at
|
|
43
|
+
#
|
|
44
|
+
# * http://rubyforge.org/frs?group_id=953
|
|
45
|
+
#
|
|
46
|
+
# Online Documentation should be located at
|
|
47
|
+
#
|
|
48
|
+
# * http://json.rubyforge.org
|
|
49
|
+
#
|
|
50
|
+
# == Usage
|
|
51
|
+
#
|
|
52
|
+
# To use JSON you can
|
|
53
|
+
# require 'json'
|
|
54
|
+
# to load the installed variant (either the extension 'json' or the pure
|
|
55
|
+
# variant 'json_pure'). If you have installed the extension variant, you can
|
|
56
|
+
# pick either the extension variant or the pure variant by typing
|
|
57
|
+
# require 'json/ext'
|
|
58
|
+
# or
|
|
59
|
+
# require 'json/pure'
|
|
60
|
+
#
|
|
61
|
+
# You can choose to load a set of common additions to ruby core's objects if
|
|
62
|
+
# you
|
|
63
|
+
# require 'json/add/core'
|
|
64
|
+
#
|
|
65
|
+
# After requiring this you can, e. g., serialise/deserialise Ruby ranges:
|
|
66
|
+
#
|
|
67
|
+
# JSON JSON(1..10) # => 1..10
|
|
68
|
+
#
|
|
69
|
+
# To find out how to add JSON support to other or your own classes, read the
|
|
70
|
+
# Examples section below.
|
|
71
|
+
#
|
|
72
|
+
# To get the best compatibility to rails' JSON implementation, you can
|
|
73
|
+
# require 'json/add/rails'
|
|
74
|
+
#
|
|
75
|
+
# Both of the additions attempt to require 'json' (like above) first, if it has
|
|
76
|
+
# not been required yet.
|
|
77
|
+
#
|
|
78
|
+
# == Speed Comparisons
|
|
79
|
+
#
|
|
80
|
+
# I have created some benchmark results (see the benchmarks subdir of the
|
|
81
|
+
# package) for the JSON-Parser to estimate the speed up in the C extension:
|
|
82
|
+
#
|
|
83
|
+
# JSON::Pure::Parser:: 28.90 calls/second
|
|
84
|
+
# JSON::Ext::Parser:: 505.50 calls/second
|
|
85
|
+
#
|
|
86
|
+
# This is ca. <b>17.5</b> times the speed of the pure Ruby implementation.
|
|
87
|
+
#
|
|
88
|
+
# I have benchmarked the JSON-Generator as well. This generates a few more
|
|
89
|
+
# values, because there are different modes, that also influence the achieved
|
|
90
|
+
# speed:
|
|
91
|
+
#
|
|
92
|
+
# * JSON::Pure::Generator:
|
|
93
|
+
# generate:: 35.06 calls/second
|
|
94
|
+
# pretty_generate:: 34.00 calls/second
|
|
95
|
+
# fast_generate:: 41.06 calls/second
|
|
96
|
+
#
|
|
97
|
+
# * JSON::Ext::Generator:
|
|
98
|
+
# generate:: 492.11 calls/second
|
|
99
|
+
# pretty_generate:: 348.85 calls/second
|
|
100
|
+
# fast_generate:: 541.60 calls/second
|
|
101
|
+
#
|
|
102
|
+
# * Speedup Ext/Pure:
|
|
103
|
+
# generate safe:: 14.0 times
|
|
104
|
+
# generate pretty:: 10.3 times
|
|
105
|
+
# generate fast:: 13.2 times
|
|
106
|
+
#
|
|
107
|
+
# The rails framework includes a generator as well, also it seems to be rather
|
|
108
|
+
# slow: I measured only 23.87 calls/second which is slower than any of my pure
|
|
109
|
+
# generator results. Here a comparison of the different speedups with the Rails
|
|
110
|
+
# measurement as the divisor:
|
|
111
|
+
#
|
|
112
|
+
# * Speedup Pure/Rails:
|
|
113
|
+
# generate safe:: 1.5 times
|
|
114
|
+
# generate pretty:: 1.4 times
|
|
115
|
+
# generate fast:: 1.7 times
|
|
116
|
+
#
|
|
117
|
+
# * Speedup Ext/Rails:
|
|
118
|
+
# generate safe:: 20.6 times
|
|
119
|
+
# generate pretty:: 14.6 times
|
|
120
|
+
# generate fast:: 22.7 times
|
|
121
|
+
#
|
|
122
|
+
# To achieve the fastest JSON text output, you can use the
|
|
123
|
+
# fast_generate/fast_unparse methods. Beware, that this will disable the
|
|
124
|
+
# checking for circular Ruby data structures, which may cause JSON to go into
|
|
125
|
+
# an infinite loop.
|
|
126
|
+
#
|
|
127
|
+
# == Examples
|
|
128
|
+
#
|
|
129
|
+
# To create a JSON text from a ruby data structure, you
|
|
130
|
+
# can call JSON.generate (or JSON.unparse) like that:
|
|
131
|
+
#
|
|
132
|
+
# json = JSON.generate [1, 2, {"a"=>3.141}, false, true, nil, 4..10]
|
|
133
|
+
# # => "[1,2,{\"a\":3.141},false,true,null,\"4..10\"]"
|
|
134
|
+
#
|
|
135
|
+
# To create a valid JSON text you have to make sure, that the output is
|
|
136
|
+
# embedded in either a JSON array [] or a JSON object {}. The easiest way to do
|
|
137
|
+
# this, is by putting your values in a Ruby Array or Hash instance.
|
|
138
|
+
#
|
|
139
|
+
# To get back a ruby data structure from a JSON text, you have to call
|
|
140
|
+
# JSON.parse on it:
|
|
141
|
+
#
|
|
142
|
+
# JSON.parse json
|
|
143
|
+
# # => [1, 2, {"a"=>3.141}, false, true, nil, "4..10"]
|
|
144
|
+
#
|
|
145
|
+
# Note, that the range from the original data structure is a simple
|
|
146
|
+
# string now. The reason for this is, that JSON doesn't support ranges
|
|
147
|
+
# or arbitrary classes. In this case the json library falls back to call
|
|
148
|
+
# Object#to_json, which is the same as #to_s.to_json.
|
|
149
|
+
#
|
|
150
|
+
# It's possible to add JSON support serialization to arbitrary classes by
|
|
151
|
+
# simply implementing a more specialized version of the #to_json method, that
|
|
152
|
+
# should return a JSON object (a hash converted to JSON with #to_json) like
|
|
153
|
+
# this (don't forget the *a for all the arguments):
|
|
154
|
+
#
|
|
155
|
+
# class Range
|
|
156
|
+
# def to_json(*a)
|
|
157
|
+
# {
|
|
158
|
+
# 'json_class' => self.class.name, # = 'Range'
|
|
159
|
+
# 'data' => [ first, last, exclude_end? ]
|
|
160
|
+
# }.to_json(*a)
|
|
161
|
+
# end
|
|
162
|
+
# end
|
|
163
|
+
#
|
|
164
|
+
# The hash key 'json_class' is the class, that will be asked to deserialise the
|
|
165
|
+
# JSON representation later. In this case it's 'Range', but any namespace of
|
|
166
|
+
# the form 'A::B' or '::A::B' will do. All other keys are arbitrary and can be
|
|
167
|
+
# used to store the necessary data to configure the object to be deserialised.
|
|
168
|
+
#
|
|
169
|
+
# If a the key 'json_class' is found in a JSON object, the JSON parser checks
|
|
170
|
+
# if the given class responds to the json_create class method. If so, it is
|
|
171
|
+
# called with the JSON object converted to a Ruby hash. So a range can
|
|
172
|
+
# be deserialised by implementing Range.json_create like this:
|
|
173
|
+
#
|
|
174
|
+
# class Range
|
|
175
|
+
# def self.json_create(o)
|
|
176
|
+
# new(*o['data'])
|
|
177
|
+
# end
|
|
178
|
+
# end
|
|
179
|
+
#
|
|
180
|
+
# Now it possible to serialise/deserialise ranges as well:
|
|
181
|
+
#
|
|
182
|
+
# json = JSON.generate [1, 2, {"a"=>3.141}, false, true, nil, 4..10]
|
|
183
|
+
# # => "[1,2,{\"a\":3.141},false,true,null,{\"json_class\":\"Range\",\"data\":[4,10,false]}]"
|
|
184
|
+
# JSON.parse json
|
|
185
|
+
# # => [1, 2, {"a"=>3.141}, false, true, nil, 4..10]
|
|
186
|
+
#
|
|
187
|
+
# JSON.generate always creates the shortest possible string representation of a
|
|
188
|
+
# ruby data structure in one line. This good for data storage or network
|
|
189
|
+
# protocols, but not so good for humans to read. Fortunately there's also
|
|
190
|
+
# JSON.pretty_generate (or JSON.pretty_generate) that creates a more
|
|
191
|
+
# readable output:
|
|
192
|
+
#
|
|
193
|
+
# puts JSON.pretty_generate([1, 2, {"a"=>3.141}, false, true, nil, 4..10])
|
|
194
|
+
# [
|
|
195
|
+
# 1,
|
|
196
|
+
# 2,
|
|
197
|
+
# {
|
|
198
|
+
# "a": 3.141
|
|
199
|
+
# },
|
|
200
|
+
# false,
|
|
201
|
+
# true,
|
|
202
|
+
# null,
|
|
203
|
+
# {
|
|
204
|
+
# "json_class": "Range",
|
|
205
|
+
# "data": [
|
|
206
|
+
# 4,
|
|
207
|
+
# 10,
|
|
208
|
+
# false
|
|
209
|
+
# ]
|
|
210
|
+
# }
|
|
211
|
+
# ]
|
|
212
|
+
#
|
|
213
|
+
# There are also the methods Kernel#j for unparse, and Kernel#jj for
|
|
214
|
+
# pretty_unparse output to the console, that work analogous to Core Ruby's p
|
|
215
|
+
# and the pp library's pp methods.
|
|
216
|
+
#
|
|
217
|
+
# The script tools/server.rb contains a small example if you want to test, how
|
|
218
|
+
# receiving a JSON object from a webrick server in your browser with the
|
|
219
|
+
# javasript prototype library (http://www.prototypejs.org) works.
|
|
220
|
+
#
|
|
221
|
+
module JSON
|
|
222
|
+
require 'json/version'
|
|
223
|
+
|
|
224
|
+
if VARIANT_BINARY
|
|
225
|
+
require 'json/ext'
|
|
226
|
+
else
|
|
227
|
+
begin
|
|
228
|
+
require 'json/ext'
|
|
229
|
+
rescue LoadError
|
|
230
|
+
require 'json/pure'
|
|
231
|
+
end
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
JSON_LOADED = true
|
|
235
|
+
end
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
require 'rbconfig'
|
|
2
|
+
|
|
3
|
+
module Launchy
|
|
4
|
+
class Application
|
|
5
|
+
|
|
6
|
+
KNOWN_OS_FAMILIES = [ :windows, :darwin, :nix, :cygwin ]
|
|
7
|
+
|
|
8
|
+
class << self
|
|
9
|
+
def inherited(sub_class)
|
|
10
|
+
application_classes << sub_class
|
|
11
|
+
end
|
|
12
|
+
def application_classes
|
|
13
|
+
@application_classes ||= []
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def find_application_class_for(*args)
|
|
17
|
+
Launchy.log "#{self.name} : finding application classes for [#{args.join(' ')}]"
|
|
18
|
+
application_classes.find do |klass|
|
|
19
|
+
Launchy.log "#{self.name} : Trying #{klass.name}"
|
|
20
|
+
if klass.handle?(*args) then
|
|
21
|
+
true
|
|
22
|
+
else
|
|
23
|
+
false
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# find an executable in the available paths
|
|
29
|
+
# mkrf did such a good job on this I had to borrow it.
|
|
30
|
+
def find_executable(bin,*paths)
|
|
31
|
+
paths = ENV['PATH'].split(File::PATH_SEPARATOR) if paths.empty?
|
|
32
|
+
paths.each do |path|
|
|
33
|
+
file = File.join(path,bin)
|
|
34
|
+
if File.executable?(file) then
|
|
35
|
+
Launchy.log "#{self.name} : found executable #{file}"
|
|
36
|
+
return file
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
Launchy.log "#{self.name} : Unable to find `#{bin}' in #{paths.join(', ')}"
|
|
40
|
+
return nil
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# return the current 'host_os' string from ruby's configuration
|
|
44
|
+
def my_os
|
|
45
|
+
if ENV['LAUNCHY_HOST_OS'] then
|
|
46
|
+
Launchy.log "#{self.name} : Using LAUNCHY_HOST_OS override of '#{ENV['LAUNCHY_HOST_OS']}'"
|
|
47
|
+
return ENV['LAUNCHY_HOST_OS']
|
|
48
|
+
else
|
|
49
|
+
::Config::CONFIG['host_os']
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# detect what the current os is and return :windows, :darwin or :nix
|
|
54
|
+
def my_os_family(test_os = my_os)
|
|
55
|
+
case test_os
|
|
56
|
+
when /mingw/i
|
|
57
|
+
family = :windows
|
|
58
|
+
when /mswin/i
|
|
59
|
+
family = :windows
|
|
60
|
+
when /windows/i
|
|
61
|
+
family = :windows
|
|
62
|
+
when /darwin/i
|
|
63
|
+
family = :darwin
|
|
64
|
+
when /mac os/i
|
|
65
|
+
family = :darwin
|
|
66
|
+
when /solaris/i
|
|
67
|
+
family = :nix
|
|
68
|
+
when /bsd/i
|
|
69
|
+
family = :nix
|
|
70
|
+
when /linux/i
|
|
71
|
+
family = :nix
|
|
72
|
+
when /aix/i
|
|
73
|
+
family = :nix
|
|
74
|
+
when /cygwin/i
|
|
75
|
+
family = :cygwin
|
|
76
|
+
else
|
|
77
|
+
$stderr.puts "Unknown OS familiy for '#{test_os}'. Please report this bug to #{Launchy::SPEC.email}"
|
|
78
|
+
family = :unknown
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
# Determine the appropriate desktop environment for *nix machine. Currently this is
|
|
85
|
+
# linux centric. The detection is based upon the detection used by xdg-open from
|
|
86
|
+
# http://portland.freedesktop.org/wiki/XdgUtils
|
|
87
|
+
def nix_desktop_environment
|
|
88
|
+
if not @nix_desktop_environment then
|
|
89
|
+
@nix_desktop_environment = :generic
|
|
90
|
+
if ENV["KDE_FULL_SESSION"] || ENV["KDE_SESSION_UID"] then
|
|
91
|
+
@nix_desktop_environment = :kde
|
|
92
|
+
elsif ENV["GNOME_DESKTOP_SESSION_ID"] then
|
|
93
|
+
@nix_desktop_environment = :gnome
|
|
94
|
+
elsif find_executable("xprop") then
|
|
95
|
+
if %x[ xprop -root _DT_SAVE_MODE | grep ' = \"xfce\"$' ].strip.size > 0 then
|
|
96
|
+
@nix_desktop_environment = :xfce
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
Launchy.log "#{self.class.name} : nix_desktop_environment => '#{@nix_desktop_environment}'"
|
|
100
|
+
end
|
|
101
|
+
return @nix_desktop_environment
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
# find an executable in the available paths
|
|
105
|
+
def find_executable(bin,*paths)
|
|
106
|
+
Application.find_executable(bin,*paths)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
# return the current 'host_os' string from ruby's configuration
|
|
110
|
+
def my_os
|
|
111
|
+
Application.my_os
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
# detect what the current os is and return :windows, :darwin, :nix, or :cygwin
|
|
115
|
+
def my_os_family(test_os = my_os)
|
|
116
|
+
Application.my_os_family(test_os)
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
# returns the list of command line application names for the current os. The list
|
|
120
|
+
# returned should only contain appliations or commands that actually exist on the
|
|
121
|
+
# system. The list members should have their full path to the executable.
|
|
122
|
+
def app_list
|
|
123
|
+
@app_list ||= self.send("#{my_os_family}_app_list")
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
# On darwin a good general default is the 'open' executable.
|
|
127
|
+
def darwin_app_list
|
|
128
|
+
Launchy.log "#{self.class.name} : Using 'open' application on darwin."
|
|
129
|
+
[ find_executable('open') ]
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
# On windows a good general default is the 'start' Command Shell command
|
|
133
|
+
def windows_app_list
|
|
134
|
+
Launchy.log "#{self.class.name} : Using 'start' command on windows."
|
|
135
|
+
%w[ start ]
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
# Cygwin uses the windows start but through an explicit execution of the cmd shell
|
|
139
|
+
def cygwin_app_list
|
|
140
|
+
Launchy.log "#{self.class.name} : Using 'cmd /C start' on windows."
|
|
141
|
+
[ "cmd /C start" ]
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
# run the command
|
|
145
|
+
def run(cmd,*args)
|
|
146
|
+
args.unshift(cmd)
|
|
147
|
+
cmd_line = args.join(' ')
|
|
148
|
+
Launchy.log "#{self.class.name} : Spawning on #{my_os_family} : #{cmd_line}"
|
|
149
|
+
|
|
150
|
+
if my_os_family == :windows then
|
|
151
|
+
system cmd_line
|
|
152
|
+
else
|
|
153
|
+
# fork, and the child process should NOT run any exit handlers
|
|
154
|
+
child_pid = fork do
|
|
155
|
+
cmd_line += " > /dev/null 2>&1"
|
|
156
|
+
system cmd_line
|
|
157
|
+
exit!
|
|
158
|
+
end
|
|
159
|
+
Process.detach(child_pid)
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
end
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
require 'launchy/application'
|
|
2
|
+
require 'uri'
|
|
3
|
+
|
|
4
|
+
module Launchy
|
|
5
|
+
class Browser < Application
|
|
6
|
+
|
|
7
|
+
DESKTOP_ENVIRONMENT_BROWSER_LAUNCHERS = {
|
|
8
|
+
:kde => "kfmclient",
|
|
9
|
+
:gnome => "gnome-open",
|
|
10
|
+
:xfce => "exo-open",
|
|
11
|
+
:generic => "htmlview"
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
FALLBACK_BROWSERS = %w[ firefox seamonkey opera mozilla netscape galeon ]
|
|
15
|
+
|
|
16
|
+
class << self
|
|
17
|
+
def run(*args)
|
|
18
|
+
Browser.new.visit(args[0])
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# return true if this class can handle the given parameter(s)
|
|
22
|
+
def handle?(*args)
|
|
23
|
+
begin
|
|
24
|
+
Launchy.log "#{self.name} : testing if [#{args[0]}] (#{args[0].class}) is a url."
|
|
25
|
+
uri = URI.parse(args[0])
|
|
26
|
+
result = [URI::HTTP, URI::HTTPS, URI::FTP].include?(uri.class)
|
|
27
|
+
rescue Exception => e
|
|
28
|
+
# hmm... why does rcov not see that this is executed ?
|
|
29
|
+
Launchy.log "#{self.name} : not a url, #{e}"
|
|
30
|
+
return false
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def initialize
|
|
36
|
+
raise "Unable to find browser to launch for os family '#{my_os_family}'." unless browser
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Find a list of potential browser applications to run on *nix machines.
|
|
40
|
+
# The order is:
|
|
41
|
+
# 1) What is in ENV['LAUNCHY_BROWSER'] or ENV['BROWSER']
|
|
42
|
+
# 2) xdg-open
|
|
43
|
+
# 3) desktop environment launcher program
|
|
44
|
+
# 4) a list of fallback browsers
|
|
45
|
+
def nix_app_list
|
|
46
|
+
if not @nix_app_list then
|
|
47
|
+
browser_cmds = ['xdg-open']
|
|
48
|
+
browser_cmds << DESKTOP_ENVIRONMENT_BROWSER_LAUNCHERS[nix_desktop_environment]
|
|
49
|
+
browser_cmds << FALLBACK_BROWSERS
|
|
50
|
+
browser_cmds.flatten!
|
|
51
|
+
browser_cmds.delete_if { |b| b.nil? || (b.strip.size == 0) }
|
|
52
|
+
Launchy.log "#{self.class.name} : Initial *Nix Browser List: #{browser_cmds.join(', ')}"
|
|
53
|
+
@nix_app_list = browser_cmds.collect { |bin| find_executable(bin) }.find_all { |x| not x.nil? }
|
|
54
|
+
Launchy.log "#{self.class.name} : Filtered *Nix Browser List: #{@nix_app_list.join(', ')}"
|
|
55
|
+
end
|
|
56
|
+
@nix_app_list
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# return the full command line path to the browser or nil
|
|
60
|
+
def browser
|
|
61
|
+
if not @browser then
|
|
62
|
+
if ENV['LAUNCHY_BROWSER'] and File.exists?(ENV['LAUNCHY_BROWSER']) then
|
|
63
|
+
Launchy.log "#{self.class.name} : Using LAUNCHY_BROWSER environment variable : #{ENV['LAUNCHY_BROWSER']}"
|
|
64
|
+
@browser = ENV['LAUNCHY_BROWSER']
|
|
65
|
+
elsif ENV['BROWSER'] and File.exists?(ENV['BROWSER']) then
|
|
66
|
+
Launchy.log "#{self.class.name} : Using BROWSER environment variable : #{ENV['BROWSER']}"
|
|
67
|
+
@browser = ENV['BROWSER']
|
|
68
|
+
elsif app_list.size > 0 then
|
|
69
|
+
@browser = app_list.first
|
|
70
|
+
Launchy.log "#{self.class.name} : Using application list : #{@browser}"
|
|
71
|
+
else
|
|
72
|
+
msg = "Unable to launch. No Browser application found."
|
|
73
|
+
Launchy.log "#{self.class.name} : #{msg}"
|
|
74
|
+
$stderr.puts msg
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
return @browser
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# launch the browser at the appointed url
|
|
81
|
+
def visit(url)
|
|
82
|
+
run(browser,url)
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
require 'optparse'
|
|
2
|
+
|
|
3
|
+
module Launchy
|
|
4
|
+
class CommandLine
|
|
5
|
+
|
|
6
|
+
def parser
|
|
7
|
+
@parser ||= OptionParser.new do |op|
|
|
8
|
+
op.banner = "Usage: launchy [options] url"
|
|
9
|
+
op.separator ""
|
|
10
|
+
op.on("-d", "--debug", "Force debug, output lots of information.",
|
|
11
|
+
"This sets the LAUNCHY_DEBUG environment variable to 'true'.") do |d|
|
|
12
|
+
ENV["LAUNCHY_DEBUG"] = 'true'
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
op.on("-h", "--help", "Print this message") do |h|
|
|
16
|
+
puts op.to_s
|
|
17
|
+
exit 0
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
op.on("-v", "--version", "Output the version of Launchy") do |v|
|
|
21
|
+
puts "Launchy version #{Launchy::VERSION}"
|
|
22
|
+
exit 0
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
op.on("-o", "--host-os HOST_OS","Force the behavior of a particular host os.",
|
|
26
|
+
"This sets the LAUNCHY_HOST_OS environment variable.") do |os|
|
|
27
|
+
ENV["LAUNCHY_HOST_OS"] = os
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
op.on("-b", "--browser BROWSER", "Force launchy to use a particular browser.",
|
|
31
|
+
"This sets the LAUNCHY_BROWSER environment variable.") do |browser|
|
|
32
|
+
ENV["LAUNCHY_BROWSER"] = browser
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def run(argv = ARGV)
|
|
38
|
+
begin
|
|
39
|
+
parser.parse!(argv)
|
|
40
|
+
Launchy.open(*argv)
|
|
41
|
+
rescue ::OptionParser::ParseError => pe
|
|
42
|
+
$stderr.puts "#{parser.programn_name}: #{pe}"
|
|
43
|
+
$stderr.puts "Try `#{parser.program_name} --help' for more information."
|
|
44
|
+
exit 1
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'launchy/specification'
|
|
3
|
+
require 'launchy/version'
|
|
4
|
+
require 'rake'
|
|
5
|
+
|
|
6
|
+
# The Gem Specification plus some extras for launchy.
|
|
7
|
+
module Launchy
|
|
8
|
+
SPEC = Launchy::Specification.new do |spec|
|
|
9
|
+
spec.name = "launchy"
|
|
10
|
+
spec.version = Launchy::VERSION
|
|
11
|
+
spec.rubyforge_project = "copiousfreetime"
|
|
12
|
+
spec.author = "Jeremy Hinegardner"
|
|
13
|
+
spec.email = "jeremy@hinegardner.org"
|
|
14
|
+
spec.homepage = "http://copiousfreetime.rubyforge.org/launchy/"
|
|
15
|
+
|
|
16
|
+
spec.summary = "A helper to launch apps from within ruby programs."
|
|
17
|
+
spec.description = <<-DESC
|
|
18
|
+
Launchy is helper class for launching cross-platform applications in a
|
|
19
|
+
fire and forget manner.
|
|
20
|
+
|
|
21
|
+
There are application concepts (browser, email client, etc) that are common
|
|
22
|
+
across all platforms, and they may be launched differently on each
|
|
23
|
+
platform. Launchy is here to make a common approach to launching
|
|
24
|
+
external application from within ruby programs.
|
|
25
|
+
|
|
26
|
+
DESC
|
|
27
|
+
|
|
28
|
+
spec.extra_rdoc_files = FileList["CHANGES", "LICENSE", "README"]
|
|
29
|
+
spec.has_rdoc = true
|
|
30
|
+
spec.rdoc_main = "README"
|
|
31
|
+
spec.rdoc_options = [ "--line-numbers" , "--inline-source" ]
|
|
32
|
+
|
|
33
|
+
spec.test_files = FileList["spec/**/*.rb", "test/**/*.rb"]
|
|
34
|
+
spec.files = spec.test_files + spec.extra_rdoc_files +
|
|
35
|
+
FileList["lib/**/*.rb", "resources/**/*"]
|
|
36
|
+
|
|
37
|
+
spec.executable = spec.name
|
|
38
|
+
|
|
39
|
+
spec.platform = Gem::Platform::RUBY
|
|
40
|
+
spec.required_ruby_version = ">= 1.8.5"
|
|
41
|
+
|
|
42
|
+
spec.local_rdoc_dir = "doc/rdoc"
|
|
43
|
+
spec.remote_rdoc_dir = ""
|
|
44
|
+
spec.local_coverage_dir = "doc/coverage"
|
|
45
|
+
spec.remote_coverage_dir= "coverage"
|
|
46
|
+
|
|
47
|
+
spec.remote_user = "jjh"
|
|
48
|
+
spec.remote_site_dir = "#{spec.name}/"
|
|
49
|
+
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
|