opal 0.3.15 → 0.3.16

Sign up to get free protection for your applications and to get access to all the features.
Files changed (236) hide show
  1. data/.gitignore +1 -1
  2. data/Gemfile +8 -2
  3. data/README.md +1 -1
  4. data/Rakefile +51 -57
  5. data/bin/opal +50 -2
  6. data/{runtime/corelib → core}/alpha.rb +6 -1
  7. data/{runtime/corelib → core}/array.rb +38 -42
  8. data/{runtime/corelib → core}/basic_object.rb +6 -17
  9. data/core/boolean.rb +40 -0
  10. data/core/class.rb +69 -0
  11. data/{runtime/corelib → core}/comparable.rb +0 -0
  12. data/core/debug.js +59 -0
  13. data/core/debug.rb +35 -0
  14. data/core/dir.rb +90 -0
  15. data/core/enumerable.rb +331 -0
  16. data/core/enumerator.rb +126 -0
  17. data/core/error.rb +40 -0
  18. data/{runtime/corelib → core}/file.rb +6 -3
  19. data/core/gemlib.rb +30 -0
  20. data/{runtime/corelib → core}/hash.rb +37 -35
  21. data/{runtime/corelib → core}/io.rb +0 -0
  22. data/{runtime/corelib → core}/kernel.rb +26 -21
  23. data/{runtime/corelib → core}/load_order +2 -5
  24. data/{runtime/corelib → core}/match_data.rb +2 -4
  25. data/core/module.rb +204 -0
  26. data/{runtime/corelib → core}/nil_class.rb +1 -7
  27. data/{runtime/corelib → core}/numeric.rb +9 -13
  28. data/core/object.rb +17 -0
  29. data/{runtime/corelib → core}/proc.rb +2 -13
  30. data/{runtime/corelib → core}/range.rb +19 -7
  31. data/{runtime/corelib → core}/rational.rb +0 -0
  32. data/{runtime/corelib → core}/regexp.rb +2 -6
  33. data/core/runtime.js +672 -0
  34. data/{runtime/corelib → core}/string.rb +25 -9
  35. data/{runtime/corelib → core}/struct.rb +0 -0
  36. data/core/time.rb +111 -0
  37. data/{runtime/corelib → core}/top_self.rb +0 -0
  38. data/{runtime/spec → core_spec}/README.md +0 -0
  39. data/{runtime/spec → core_spec}/core/array/allocate_spec.rb +0 -0
  40. data/{runtime/spec → core_spec}/core/array/append_spec.rb +0 -0
  41. data/{runtime/spec → core_spec}/core/array/assoc_spec.rb +0 -0
  42. data/{runtime/spec → core_spec}/core/array/at_spec.rb +0 -0
  43. data/{runtime/spec → core_spec}/core/array/clear_spec.rb +0 -0
  44. data/{runtime/spec → core_spec}/core/array/collect_spec.rb +0 -0
  45. data/{runtime/spec → core_spec}/core/array/compact_spec.rb +0 -0
  46. data/{runtime/spec → core_spec}/core/array/concat_spec.rb +0 -0
  47. data/{runtime/spec → core_spec}/core/array/constructor_spec.rb +0 -0
  48. data/{runtime/spec → core_spec}/core/array/count_spec.rb +0 -0
  49. data/{runtime/spec → core_spec}/core/array/delete_at_spec.rb +0 -0
  50. data/{runtime/spec → core_spec}/core/array/delete_if_spec.rb +0 -0
  51. data/{runtime/spec → core_spec}/core/array/delete_spec.rb +0 -0
  52. data/{runtime/spec → core_spec}/core/array/each_index_spec.rb +0 -0
  53. data/{runtime/spec → core_spec}/core/array/each_spec.rb +0 -0
  54. data/{runtime/spec → core_spec}/core/array/element_reference_spec.rb +0 -0
  55. data/{runtime/spec → core_spec}/core/array/element_set_spec.rb +0 -0
  56. data/{runtime/spec → core_spec}/core/array/empty_spec.rb +0 -0
  57. data/{runtime/spec → core_spec}/core/array/eql_spec.rb +0 -0
  58. data/{runtime/spec → core_spec}/core/array/equal_value_spec.rb +0 -0
  59. data/{runtime/spec → core_spec}/core/array/fetch_spec.rb +0 -0
  60. data/{runtime/spec → core_spec}/core/array/first_spec.rb +0 -0
  61. data/{runtime/spec → core_spec}/core/array/fixtures/classes.rb +0 -0
  62. data/{runtime/spec → core_spec}/core/array/flatten_spec.rb +0 -0
  63. data/{runtime/spec → core_spec}/core/array/include_spec.rb +0 -0
  64. data/{runtime/spec → core_spec}/core/array/insert_spec.rb +0 -0
  65. data/{runtime/spec → core_spec}/core/array/last_spec.rb +0 -0
  66. data/{runtime/spec → core_spec}/core/array/length_spec.rb +0 -0
  67. data/{runtime/spec → core_spec}/core/array/map_spec.rb +0 -0
  68. data/{runtime/spec → core_spec}/core/array/plus_spec.rb +0 -0
  69. data/{runtime/spec → core_spec}/core/array/pop_spec.rb +0 -0
  70. data/{runtime/spec → core_spec}/core/array/push_spec.rb +0 -0
  71. data/{runtime/spec → core_spec}/core/array/rassoc_spec.rb +0 -0
  72. data/{runtime/spec → core_spec}/core/array/reject_spec.rb +0 -0
  73. data/{runtime/spec → core_spec}/core/array/replace_spec.rb +0 -0
  74. data/{runtime/spec → core_spec}/core/array/reverse_each_spec.rb +0 -0
  75. data/{runtime/spec → core_spec}/core/array/reverse_spec.rb +0 -0
  76. data/{runtime/spec → core_spec}/core/array/shared/collect.rb +0 -0
  77. data/{runtime/spec → core_spec}/core/array/shared/eql.rb +0 -0
  78. data/{runtime/spec → core_spec}/core/array/shared/length.rb +0 -0
  79. data/{runtime/spec → core_spec}/core/array/shared/replace.rb +0 -0
  80. data/{runtime/spec → core_spec}/core/class/new_spec.rb +0 -0
  81. data/{runtime/spec → core_spec}/core/enumerable/all_spec.rb +0 -0
  82. data/{runtime/spec → core_spec}/core/enumerable/any_spec.rb +0 -0
  83. data/{runtime/spec → core_spec}/core/enumerable/collect_spec.rb +0 -0
  84. data/{runtime/spec → core_spec}/core/enumerable/count_spec.rb +0 -0
  85. data/{runtime/spec → core_spec}/core/enumerable/detect_spec.rb +0 -0
  86. data/{runtime/spec → core_spec}/core/enumerable/find_spec.rb +0 -0
  87. data/core_spec/core/enumerable/first_spec.rb +3 -0
  88. data/{runtime/spec → core_spec}/core/enumerable/fixtures/classes.rb +0 -0
  89. data/{runtime/spec → core_spec}/core/enumerable/shared/collect.rb +0 -0
  90. data/{runtime/spec → core_spec}/core/enumerable/shared/entries.rb +0 -0
  91. data/{runtime/spec → core_spec}/core/enumerable/shared/find.rb +0 -0
  92. data/core_spec/core/enumerable/shared/take.rb +31 -0
  93. data/{runtime/spec → core_spec}/core/enumerable/to_a_spec.rb +0 -0
  94. data/{runtime/spec → core_spec}/core/false/and_spec.rb +0 -0
  95. data/{runtime/spec → core_spec}/core/false/inspect_spec.rb +0 -0
  96. data/{runtime/spec → core_spec}/core/false/or_spec.rb +0 -0
  97. data/{runtime/spec → core_spec}/core/false/to_s_spec.rb +0 -0
  98. data/{runtime/spec → core_spec}/core/false/xor_spec.rb +0 -0
  99. data/{runtime/spec → core_spec}/core/hash/allocate_spec.rb +0 -0
  100. data/{runtime/spec → core_spec}/core/hash/assoc_spec.rb +0 -0
  101. data/{runtime/spec → core_spec}/core/hash/clear_spec.rb +0 -0
  102. data/{runtime/spec → core_spec}/core/hash/clone_spec.rb +0 -0
  103. data/{runtime/spec → core_spec}/core/hash/default_spec.rb +0 -0
  104. data/{runtime/spec → core_spec}/core/hash/delete_if_spec.rb +0 -0
  105. data/{runtime/spec → core_spec}/core/hash/element_reference_spec.rb +0 -0
  106. data/{runtime/spec → core_spec}/core/hash/element_set_spec.rb +0 -0
  107. data/{runtime/spec → core_spec}/core/hash/new_spec.rb +0 -0
  108. data/{runtime/spec → core_spec}/core/matchdata/to_a_spec.rb +0 -0
  109. data/{runtime/spec → core_spec}/core/nil/and_spec.rb +0 -0
  110. data/{runtime/spec → core_spec}/core/nil/inspect_spec.rb +0 -0
  111. data/{runtime/spec → core_spec}/core/nil/nil_spec.rb +0 -0
  112. data/{runtime/spec → core_spec}/core/nil/or_spec.rb +0 -0
  113. data/{runtime/spec → core_spec}/core/nil/to_a_spec.rb +0 -0
  114. data/{runtime/spec → core_spec}/core/nil/to_f_spec.rb +0 -0
  115. data/{runtime/spec → core_spec}/core/nil/to_i_spec.rb +0 -0
  116. data/{runtime/spec → core_spec}/core/nil/to_s_spec.rb +0 -0
  117. data/{runtime/spec → core_spec}/core/nil/xor_spec.rb +0 -0
  118. data/{runtime/spec → core_spec}/core/numeric/equal_value_spec.rb +0 -0
  119. data/{runtime/spec → core_spec}/core/object/is_a_spec.rb +0 -0
  120. data/{runtime/spec → core_spec}/core/object/shared/kind_of.rb +0 -0
  121. data/{runtime/spec → core_spec}/core/regexp/match_spec.rb +0 -0
  122. data/{runtime/spec → core_spec}/core/regexp/shared/match.rb +0 -0
  123. data/{runtime/spec → core_spec}/core/symbol/to_proc_spec.rb +0 -0
  124. data/{runtime/spec → core_spec}/core/true/and_spec.rb +0 -0
  125. data/{runtime/spec → core_spec}/core/true/inspect_spec.rb +0 -0
  126. data/{runtime/spec → core_spec}/core/true/or_spec.rb +0 -0
  127. data/{runtime/spec → core_spec}/core/true/to_s_spec.rb +0 -0
  128. data/{runtime/spec → core_spec}/core/true/xor_spec.rb +0 -0
  129. data/{runtime/spec → core_spec}/language/alias_spec.rb +0 -0
  130. data/{runtime/spec → core_spec}/language/and_spec.rb +0 -0
  131. data/{runtime/spec → core_spec}/language/array_spec.rb +0 -0
  132. data/{runtime/spec → core_spec}/language/block_spec.rb +0 -0
  133. data/{runtime/spec → core_spec}/language/break_spec.rb +0 -0
  134. data/{runtime/spec → core_spec}/language/case_spec.rb +0 -0
  135. data/{runtime/spec → core_spec}/language/defined_spec.rb +0 -0
  136. data/{runtime/spec → core_spec}/language/ensure_spec.rb +0 -0
  137. data/{runtime/spec → core_spec}/language/fixtures/block.rb +0 -0
  138. data/{runtime/spec → core_spec}/language/fixtures/break.rb +0 -0
  139. data/{runtime/spec → core_spec}/language/fixtures/defined.rb +0 -0
  140. data/{runtime/spec → core_spec}/language/fixtures/ensure.rb +0 -0
  141. data/{runtime/spec → core_spec}/language/fixtures/next.rb +0 -0
  142. data/{runtime/spec → core_spec}/language/fixtures/send.rb +0 -0
  143. data/{runtime/spec → core_spec}/language/fixtures/super.rb +0 -0
  144. data/{runtime/spec → core_spec}/language/hash_spec.rb +0 -0
  145. data/{runtime/spec → core_spec}/language/if_spec.rb +0 -0
  146. data/{runtime/spec → core_spec}/language/loop_spec.rb +0 -0
  147. data/{runtime/spec → core_spec}/language/next_spec.rb +0 -0
  148. data/{runtime/spec → core_spec}/language/or_spec.rb +0 -0
  149. data/{runtime/spec → core_spec}/language/predefined_spec.rb +0 -0
  150. data/{runtime/spec → core_spec}/language/regexp/interpolation_spec.rb +8 -0
  151. data/{runtime/spec → core_spec}/language/regexp_spec.rb +0 -0
  152. data/{runtime/spec → core_spec}/language/send_spec.rb +0 -0
  153. data/{runtime/spec → core_spec}/language/string_spec.rb +0 -0
  154. data/{runtime/spec → core_spec}/language/super_spec.rb +0 -0
  155. data/{runtime/spec → core_spec}/language/symbol_spec.rb +0 -0
  156. data/{runtime/spec → core_spec}/language/undef_spec.rb +0 -0
  157. data/{runtime/spec → core_spec}/language/unless_spec.rb +0 -0
  158. data/{runtime/spec → core_spec}/language/until_spec.rb +0 -0
  159. data/core_spec/language/variables_spec.rb +112 -0
  160. data/{runtime/spec → core_spec}/language/versions/hash_1.9.rb +0 -0
  161. data/{runtime/spec → core_spec}/language/while_spec.rb +0 -0
  162. data/{runtime/spec → core_spec}/opal/opal/defined_spec.rb +0 -0
  163. data/{runtime/spec → core_spec}/opal/opal/function_spec.rb +0 -0
  164. data/{runtime/spec → core_spec}/opal/opal/native_spec.rb +0 -0
  165. data/{runtime/spec → core_spec}/opal/opal/null_spec.rb +0 -0
  166. data/{runtime/spec → core_spec}/opal/opal/number_spec.rb +0 -0
  167. data/{runtime/spec → core_spec}/opal/opal/object_spec.rb +0 -0
  168. data/{runtime/spec → core_spec}/opal/opal/string_spec.rb +0 -0
  169. data/{runtime/spec → core_spec}/opal/opal/typeof_spec.rb +0 -0
  170. data/{runtime/spec → core_spec}/opal/opal/undefined_spec.rb +0 -0
  171. data/{runtime/spec → core_spec}/opal/true/case_compare_spec.rb +0 -0
  172. data/{runtime/spec → core_spec}/opal/true/class_spec.rb +0 -0
  173. data/{docs/spec_runner.html → core_spec/release_runner.html} +4 -3
  174. data/core_spec/runner.html +16 -0
  175. data/core_spec/spec_helper.rb +23 -0
  176. data/lib/opal.rb +85 -2
  177. data/lib/opal/builder.rb +129 -46
  178. data/lib/opal/context.rb +47 -26
  179. data/lib/opal/dependency_builder.rb +113 -14
  180. data/lib/opal/environment.rb +40 -45
  181. data/lib/opal/parser/grammar.rb +2296 -2254
  182. data/lib/opal/parser/grammar.y +27 -8
  183. data/lib/opal/parser/lexer.rb +12 -3
  184. data/lib/opal/parser/parser.rb +117 -30
  185. data/lib/opal/parser/scope.rb +2 -2
  186. data/lib/opal/version.rb +1 -1
  187. data/opal.gemspec +3 -8
  188. data/spec/grammar/masgn_spec.rb +37 -0
  189. metadata +177 -227
  190. data/index.html +0 -434
  191. data/lib/opal/command.rb +0 -73
  192. data/runtime/README.md +0 -25
  193. data/runtime/corelib/boolean.rb +0 -44
  194. data/runtime/corelib/class.rb +0 -43
  195. data/runtime/corelib/complex.rb +0 -2
  196. data/runtime/corelib/dir.rb +0 -29
  197. data/runtime/corelib/enumerable.rb +0 -316
  198. data/runtime/corelib/enumerator.rb +0 -80
  199. data/runtime/corelib/error.rb +0 -25
  200. data/runtime/corelib/module.rb +0 -171
  201. data/runtime/corelib/native.rb +0 -50
  202. data/runtime/corelib/object.rb +0 -21
  203. data/runtime/corelib/time.rb +0 -196
  204. data/runtime/gemlib/alpha.rb +0 -5
  205. data/runtime/gemlib/kernel.rb +0 -17
  206. data/runtime/gemlib/load_order +0 -2
  207. data/runtime/kernel/class.js +0 -256
  208. data/runtime/kernel/debug.js +0 -42
  209. data/runtime/kernel/init.js +0 -114
  210. data/runtime/kernel/load_order +0 -5
  211. data/runtime/kernel/loader.js +0 -151
  212. data/runtime/kernel/runtime.js +0 -414
  213. data/runtime/spec/language/variables_spec.rb +0 -28
  214. data/runtime/spec/library/stringscanner/scan_spec.rb +0 -36
  215. data/runtime/spec/opal/forwardable/def_instance_delegator_spec.rb +0 -49
  216. data/runtime/spec/spec_helper.rb +0 -25
  217. data/runtime/stdlib/base64.rb +0 -91
  218. data/runtime/stdlib/date.rb +0 -4
  219. data/runtime/stdlib/dev.rb +0 -171
  220. data/runtime/stdlib/forwardable.rb +0 -33
  221. data/runtime/stdlib/optparse.rb +0 -0
  222. data/runtime/stdlib/pp.rb +0 -6
  223. data/runtime/stdlib/racc/parser.rb +0 -159
  224. data/runtime/stdlib/rbconfig.rb +0 -0
  225. data/runtime/stdlib/si.rb +0 -17
  226. data/runtime/stdlib/strscan.rb +0 -53
  227. data/runtime/stdlib/uri.rb +0 -111
  228. data/runtime/stdlib/uri/common.rb +0 -1014
  229. data/runtime/stdlib/uri/ftp.rb +0 -261
  230. data/runtime/stdlib/uri/generic.rb +0 -1599
  231. data/runtime/stdlib/uri/http.rb +0 -106
  232. data/runtime/stdlib/uri/https.rb +0 -22
  233. data/runtime/stdlib/uri/ldap.rb +0 -260
  234. data/runtime/stdlib/uri/ldaps.rb +0 -20
  235. data/runtime/stdlib/uri/mailto.rb +0 -280
  236. data/spec/builder/output_path_spec.rb +0 -50
@@ -1,106 +0,0 @@
1
- # = uri/http.rb
2
- #
3
- # Author:: Akira Yamada <akira@ruby-lang.org>
4
- # License:: You can redistribute it and/or modify it under the same term as Ruby.
5
- # Revision:: $Id$
6
- #
7
- # See URI for general documentation
8
- #
9
-
10
- require 'uri/generic'
11
-
12
- module URI
13
-
14
- #
15
- # The syntax of HTTP URIs is defined in RFC1738 section 3.3.
16
- #
17
- # Note that the Ruby URI library allows HTTP URLs containing usernames and
18
- # passwords. This is not legal as per the RFC, but used to be
19
- # supported in Internet Explorer 5 and 6, before the MS04-004 security
20
- # update. See <URL:http://support.microsoft.com/kb/834489>.
21
- #
22
- class HTTP < Generic
23
- # A Default port of 80 for URI::HTTP
24
- DEFAULT_PORT = 80
25
-
26
- # An Array of the available components for URI::HTTP
27
- COMPONENT = [
28
- :scheme,
29
- :userinfo, :host, :port,
30
- :path,
31
- :query,
32
- :fragment
33
- ].freeze
34
-
35
- #
36
- # == Description
37
- #
38
- # Create a new URI::HTTP object from components, with syntax checking.
39
- #
40
- # The components accepted are userinfo, host, port, path, query and
41
- # fragment.
42
- #
43
- # The components should be provided either as an Array, or as a Hash
44
- # with keys formed by preceding the component names with a colon.
45
- #
46
- # If an Array is used, the components must be passed in the order
47
- # [userinfo, host, port, path, query, fragment].
48
- #
49
- # Example:
50
- #
51
- # newuri = URI::HTTP.build({:host => 'www.example.com',
52
- # :path> => '/foo/bar'})
53
- #
54
- # newuri = URI::HTTP.build([nil, "www.example.com", nil, "/path",
55
- # "query", 'fragment'])
56
- #
57
- # Currently, if passed userinfo components this method generates
58
- # invalid HTTP URIs as per RFC 1738.
59
- #
60
- def self.build(args)
61
- tmp = Util::make_components_hash(self, args)
62
- return super(tmp)
63
- end
64
-
65
- #
66
- # == Description
67
- #
68
- # Create a new URI::HTTP object from generic URI components as per
69
- # RFC 2396. No HTTP-specific syntax checking (as per RFC 1738) is
70
- # performed.
71
- #
72
- # Arguments are +scheme+, +userinfo+, +host+, +port+, +registry+, +path+,
73
- # +opaque+, +query+ and +fragment+, in that order.
74
- #
75
- # Example:
76
- #
77
- # uri = URI::HTTP.new('http', nil, "www.example.com", nil, "/path",
78
- # "query", 'fragment')
79
- #
80
- #
81
- # See also URI::Generic.new
82
- #
83
- def initialize(*arg)
84
- super(*arg)
85
- end
86
-
87
- #
88
- # == Description
89
- #
90
- # Returns the full path for an HTTP request, as required by Net::HTTP::Get.
91
- #
92
- # If the URI contains a query, the full path is URI#path + '?' + URI#query.
93
- # Otherwise, the path is simply URI#path.
94
- #
95
- def request_uri
96
- r = path_query
97
- if r && r[0] != ?/
98
- r = '/' + r
99
- end
100
-
101
- r
102
- end
103
- end
104
-
105
- @@schemes['HTTP'] = HTTP
106
- end
@@ -1,22 +0,0 @@
1
- # = uri/https.rb
2
- #
3
- # Author:: Akira Yamada <akira@ruby-lang.org>
4
- # License:: You can redistribute it and/or modify it under the same term as Ruby.
5
- # Revision:: $Id$
6
- #
7
- # See URI for general documentation
8
- #
9
-
10
- require 'uri/http'
11
-
12
- module URI
13
-
14
- # The default port for HTTPS URIs is 443, and the scheme is 'https:' rather
15
- # than 'http:'. Other than that, HTTPS URIs are identical to HTTP URIs;
16
- # see URI::HTTP.
17
- class HTTPS < HTTP
18
- # A Default port of 443 for URI::HTTPS
19
- DEFAULT_PORT = 443
20
- end
21
- @@schemes['HTTPS'] = HTTPS
22
- end
@@ -1,260 +0,0 @@
1
- # = uri/ldap.rb
2
- #
3
- # Author::
4
- # Takaaki Tateishi <ttate@jaist.ac.jp>
5
- # Akira Yamada <akira@ruby-lang.org>
6
- # License::
7
- # URI::LDAP is copyrighted free software by Takaaki Tateishi and Akira Yamada.
8
- # You can redistribute it and/or modify it under the same term as Ruby.
9
- # Revision:: $Id$
10
- #
11
- # See URI for general documentation
12
- #
13
-
14
- require 'uri/generic'
15
-
16
- module URI
17
-
18
- #
19
- # LDAP URI SCHEMA (described in RFC2255)
20
- # ldap://<host>/<dn>[?<attrs>[?<scope>[?<filter>[?<extensions>]]]]
21
- #
22
- class LDAP < Generic
23
-
24
- # A Default port of 389 for URI::LDAP
25
- DEFAULT_PORT = 389
26
-
27
- # An Array of the available components for URI::LDAP
28
- COMPONENT = [
29
- :scheme,
30
- :host, :port,
31
- :dn,
32
- :attributes,
33
- :scope,
34
- :filter,
35
- :extensions,
36
- ].freeze
37
-
38
- # Scopes available for the starting point.
39
- #
40
- # * SCOPE_BASE - the Base DN
41
- # * SCOPE_ONE - one level under the Base DN, not including the base DN and
42
- # not including any entries under this.
43
- # * SCOPE_SUB - subtress, all entries at all levels
44
- #
45
- SCOPE = [
46
- SCOPE_ONE = 'one',
47
- SCOPE_SUB = 'sub',
48
- SCOPE_BASE = 'base',
49
- ].freeze
50
-
51
- #
52
- # == Description
53
- #
54
- # Create a new URI::LDAP object from components, with syntax checking.
55
- #
56
- # The components accepted are host, port, dn, attributes,
57
- # scope, filter, and extensions.
58
- #
59
- # The components should be provided either as an Array, or as a Hash
60
- # with keys formed by preceding the component names with a colon.
61
- #
62
- # If an Array is used, the components must be passed in the order
63
- # [host, port, dn, attributes, scope, filter, extensions].
64
- #
65
- # Example:
66
- #
67
- # newuri = URI::LDAP.build({:host => 'ldap.example.com',
68
- # :dn> => '/dc=example'})
69
- #
70
- # newuri = URI::LDAP.build(["ldap.example.com", nil,
71
- # "/dc=example;dc=com", "query", nil, nil, nil])
72
- #
73
- def self.build(args)
74
- tmp = Util::make_components_hash(self, args)
75
-
76
- if tmp[:dn]
77
- tmp[:path] = tmp[:dn]
78
- end
79
-
80
- query = []
81
- [:extensions, :filter, :scope, :attributes].collect do |x|
82
- next if !tmp[x] && query.size == 0
83
- query.unshift(tmp[x])
84
- end
85
-
86
- tmp[:query] = query.join('?')
87
-
88
- return super(tmp)
89
- end
90
-
91
- #
92
- # == Description
93
- #
94
- # Create a new URI::LDAP object from generic URI components as per
95
- # RFC 2396. No LDAP-specific syntax checking is performed.
96
- #
97
- # Arguments are +scheme+, +userinfo+, +host+, +port+, +registry+, +path+,
98
- # +opaque+, +query+ and +fragment+, in that order.
99
- #
100
- # Example:
101
- #
102
- # uri = URI::LDAP.new("ldap", nil, "ldap.example.com", nil,
103
- # "/dc=example;dc=com", "query", nil, nil, nil, nil)
104
- #
105
- #
106
- # See also URI::Generic.new
107
- #
108
- def initialize(*arg)
109
- super(*arg)
110
-
111
- if @fragment
112
- raise InvalidURIError, 'bad LDAP URL'
113
- end
114
-
115
- parse_dn
116
- parse_query
117
- end
118
-
119
- # private method to cleanup +dn+ from using the +path+ component attribute
120
- def parse_dn
121
- @dn = @path[1..-1]
122
- end
123
- private :parse_dn
124
-
125
- # private method to cleanup +attributes+, +scope+, +filter+ and +extensions+,
126
- # from using the +query+ component attribute
127
- def parse_query
128
- @attributes = nil
129
- @scope = nil
130
- @filter = nil
131
- @extensions = nil
132
-
133
- if @query
134
- attrs, scope, filter, extensions = @query.split('?')
135
-
136
- @attributes = attrs if attrs && attrs.size > 0
137
- @scope = scope if scope && scope.size > 0
138
- @filter = filter if filter && filter.size > 0
139
- @extensions = extensions if extensions && extensions.size > 0
140
- end
141
- end
142
- private :parse_query
143
-
144
- # private method to assemble +query+ from +attributes+, +scope+, +filter+ and +extensions+.
145
- def build_path_query
146
- @path = '/' + @dn
147
-
148
- query = []
149
- [@extensions, @filter, @scope, @attributes].each do |x|
150
- next if !x && query.size == 0
151
- query.unshift(x)
152
- end
153
- @query = query.join('?')
154
- end
155
- private :build_path_query
156
-
157
- # returns dn.
158
- def dn
159
- @dn
160
- end
161
-
162
- # private setter for dn +val+
163
- def set_dn(val)
164
- @dn = val
165
- build_path_query
166
- @dn
167
- end
168
- protected :set_dn
169
-
170
- # setter for dn +val+
171
- def dn=(val)
172
- set_dn(val)
173
- val
174
- end
175
-
176
- # returns attributes.
177
- def attributes
178
- @attributes
179
- end
180
-
181
- # private setter for attributes +val+
182
- def set_attributes(val)
183
- @attributes = val
184
- build_path_query
185
- @attributes
186
- end
187
- protected :set_attributes
188
-
189
- # setter for attributes +val+
190
- def attributes=(val)
191
- set_attributes(val)
192
- val
193
- end
194
-
195
- # returns scope.
196
- def scope
197
- @scope
198
- end
199
-
200
- # private setter for scope +val+
201
- def set_scope(val)
202
- @scope = val
203
- build_path_query
204
- @scope
205
- end
206
- protected :set_scope
207
-
208
- # setter for scope +val+
209
- def scope=(val)
210
- set_scope(val)
211
- val
212
- end
213
-
214
- # returns filter.
215
- def filter
216
- @filter
217
- end
218
-
219
- # private setter for filter +val+
220
- def set_filter(val)
221
- @filter = val
222
- build_path_query
223
- @filter
224
- end
225
- protected :set_filter
226
-
227
- # setter for filter +val+
228
- def filter=(val)
229
- set_filter(val)
230
- val
231
- end
232
-
233
- # returns extensions.
234
- def extensions
235
- @extensions
236
- end
237
-
238
- # private setter for extensions +val+
239
- def set_extensions(val)
240
- @extensions = val
241
- build_path_query
242
- @extensions
243
- end
244
- protected :set_extensions
245
-
246
- # setter for extensions +val+
247
- def extensions=(val)
248
- set_extensions(val)
249
- val
250
- end
251
-
252
- # Checks if URI has a path
253
- # For URI::LDAP this will return +false+
254
- def hierarchical?
255
- false
256
- end
257
- end
258
-
259
- @@schemes['LDAP'] = LDAP
260
- end
@@ -1,20 +0,0 @@
1
- # = uri/ldap.rb
2
- #
3
- # License:: You can redistribute it and/or modify it under the same term as Ruby.
4
- #
5
- # See URI for general documentation
6
- #
7
-
8
- require 'uri/ldap'
9
-
10
- module URI
11
-
12
- # The default port for LDAPS URIs is 636, and the scheme is 'ldaps:' rather
13
- # than 'ldap:'. Other than that, LDAPS URIs are identical to LDAP URIs;
14
- # see URI::LDAP.
15
- class LDAPS < LDAP
16
- # A Default port of 636 for URI::LDAPS
17
- DEFAULT_PORT = 636
18
- end
19
- @@schemes['LDAPS'] = LDAPS
20
- end
@@ -1,280 +0,0 @@
1
- # = uri/mailto.rb
2
- #
3
- # Author:: Akira Yamada <akira@ruby-lang.org>
4
- # License:: You can redistribute it and/or modify it under the same term as Ruby.
5
- # Revision:: $Id$
6
- #
7
- # See URI for general documentation
8
- #
9
-
10
- require 'uri/generic'
11
-
12
- module URI
13
-
14
- #
15
- # RFC2368, The mailto URL scheme
16
- #
17
- class MailTo < Generic
18
- include REGEXP
19
-
20
- # A Default port of nil for URI::MailTo
21
- DEFAULT_PORT = nil
22
-
23
- # An Array of the available components for URI::MailTo
24
- COMPONENT = [ :scheme, :to, :headers ].freeze
25
-
26
- # :stopdoc:
27
- # "hname" and "hvalue" are encodings of an RFC 822 header name and
28
- # value, respectively. As with "to", all URL reserved characters must
29
- # be encoded.
30
- #
31
- # "#mailbox" is as specified in RFC 822 [RFC822]. This means that it
32
- # consists of zero or more comma-separated mail addresses, possibly
33
- # including "phrase" and "comment" components. Note that all URL
34
- # reserved characters in "to" must be encoded: in particular,
35
- # parentheses, commas, and the percent sign ("%"), which commonly occur
36
- # in the "mailbox" syntax.
37
- #
38
- # Within mailto URLs, the characters "?", "=", "&" are reserved.
39
-
40
- # hname = *urlc
41
- # hvalue = *urlc
42
- # header = hname "=" hvalue
43
- HEADER_PATTERN = "(?:[^?=&]*=[^?=&]*)".freeze
44
- HEADER_REGEXP = Regexp.new(HEADER_PATTERN).freeze
45
- # headers = "?" header *( "&" header )
46
- # to = #mailbox
47
- # mailtoURL = "mailto:" [ to ] [ headers ]
48
- MAILBOX_PATTERN = "(?:#{PATTERN::ESCAPED}|[^(),%?=&])".freeze
49
- MAILTO_REGEXP = Regexp.new(" # :nodoc:
50
- \\A
51
- (#{MAILBOX_PATTERN}*?) (?# 1: to)
52
- (?:
53
- \\?
54
- (#{HEADER_PATTERN}(?:\\&#{HEADER_PATTERN})*) (?# 2: headers)
55
- )?
56
- (?:
57
- \\#
58
- (#{PATTERN::FRAGMENT}) (?# 3: fragment)
59
- )?
60
- \\z
61
- ", Regexp::EXTENDED).freeze
62
- # :startdoc:
63
-
64
- #
65
- # == Description
66
- #
67
- # Creates a new URI::MailTo object from components, with syntax checking.
68
- #
69
- # Components can be provided as an Array or Hash. If an Array is used,
70
- # the components must be supplied as [to, headers].
71
- #
72
- # If a Hash is used, the keys are the component names preceded by colons.
73
- #
74
- # The headers can be supplied as a pre-encoded string, such as
75
- # "subject=subscribe&cc=address", or as an Array of Arrays like
76
- # [['subject', 'subscribe'], ['cc', 'address']]
77
- #
78
- # Examples:
79
- #
80
- # require 'uri'
81
- #
82
- # m1 = URI::MailTo.build(['joe@example.com', 'subject=Ruby'])
83
- # puts m1.to_s -> mailto:joe@example.com?subject=Ruby
84
- #
85
- # m2 = URI::MailTo.build(['john@example.com', [['Subject', 'Ruby'], ['Cc', 'jack@example.com']]])
86
- # puts m2.to_s -> mailto:john@example.com?Subject=Ruby&Cc=jack@example.com
87
- #
88
- # m3 = URI::MailTo.build({:to => 'listman@example.com', :headers => [['subject', 'subscribe']]})
89
- # puts m3.to_s -> mailto:listman@example.com?subject=subscribe
90
- #
91
- def self.build(args)
92
- tmp = Util::make_components_hash(self, args)
93
-
94
- if tmp[:to]
95
- tmp[:opaque] = tmp[:to]
96
- else
97
- tmp[:opaque] = ''
98
- end
99
-
100
- if tmp[:headers]
101
- tmp[:opaque] << '?'
102
-
103
- if tmp[:headers].kind_of?(Array)
104
- tmp[:opaque] << tmp[:headers].collect { |x|
105
- if x.kind_of?(Array)
106
- x[0] + '=' + x[1..-1].to_s
107
- else
108
- x.to_s
109
- end
110
- }.join('&')
111
-
112
- elsif tmp[:headers].kind_of?(Hash)
113
- tmp[:opaque] << tmp[:headers].collect { |h,v|
114
- h + '=' + v
115
- }.join('&')
116
-
117
- else
118
- tmp[:opaque] << tmp[:headers].to_s
119
- end
120
- end
121
-
122
- return super(tmp)
123
- end
124
-
125
- #
126
- # == Description
127
- #
128
- # Creates a new URI::MailTo object from generic URL components with
129
- # no syntax checking.
130
- #
131
- # This method is usually called from URI::parse, which checks
132
- # the validity of each component.
133
- #
134
- def initialize(*arg)
135
- super(*arg)
136
-
137
- @to = nil
138
- @headers = []
139
-
140
- if MAILTO_REGEXP =~ @opaque
141
- if arg[-1]
142
- self.to = $1
143
- self.headers = $2
144
- else
145
- set_to($1)
146
- set_headers($2)
147
- end
148
-
149
- else
150
- raise InvalidComponentError,
151
- "unrecognised opaque part for mailtoURL: #{@opaque}"
152
- end
153
- end
154
-
155
- # The primary e-mail address of the URL, as a String
156
- attr_reader :to
157
-
158
- # E-mail headers set by the URL, as an Array of Arrays
159
- attr_reader :headers
160
-
161
- # check the to +v+ component against either
162
- # * URI::Parser Regexp for :OPAQUE
163
- # * MAILBOX_PATTERN
164
- def check_to(v)
165
- return true unless v
166
- return true if v.size == 0
167
-
168
- if parser.regexp[:OPAQUE] !~ v || /\A#{MAILBOX_PATTERN}*\z/o !~ v
169
- raise InvalidComponentError,
170
- "bad component(expected opaque component): #{v}"
171
- end
172
-
173
- return true
174
- end
175
- private :check_to
176
-
177
- # private setter for to +v+
178
- def set_to(v)
179
- @to = v
180
- end
181
- protected :set_to
182
-
183
- # setter for to +v+
184
- def to=(v)
185
- check_to(v)
186
- set_to(v)
187
- v
188
- end
189
-
190
- # check the headers +v+ component against either
191
- # * URI::Parser Regexp for :OPAQUE
192
- # * HEADER_PATTERN
193
- def check_headers(v)
194
- return true unless v
195
- return true if v.size == 0
196
-
197
- if parser.regexp[:OPAQUE] !~ v ||
198
- /\A(#{HEADER_PATTERN}(?:\&#{HEADER_PATTERN})*)\z/o !~ v
199
- raise InvalidComponentError,
200
- "bad component(expected opaque component): #{v}"
201
- end
202
-
203
- return true
204
- end
205
- private :check_headers
206
-
207
- # private setter for headers +v+
208
- def set_headers(v)
209
- @headers = []
210
- if v
211
- v.scan(HEADER_REGEXP) do |x|
212
- @headers << x.split(/=/o, 2)
213
- end
214
- end
215
- end
216
- protected :set_headers
217
-
218
- # setter for headers +v+
219
- def headers=(v)
220
- check_headers(v)
221
- set_headers(v)
222
- v
223
- end
224
-
225
- # Constructs String from URI
226
- def to_s
227
- @scheme + ':' +
228
- if @to
229
- @to
230
- else
231
- ''
232
- end +
233
- if @headers.size > 0
234
- '?' + @headers.collect{|x| x.join('=')}.join('&')
235
- else
236
- ''
237
- end +
238
- if @fragment
239
- '#' + @fragment
240
- else
241
- ''
242
- end
243
- end
244
-
245
- # Returns the RFC822 e-mail text equivalent of the URL, as a String.
246
- #
247
- # Example:
248
- #
249
- # require 'uri'
250
- #
251
- # uri = URI.parse("mailto:ruby-list@ruby-lang.org?Subject=subscribe&cc=myaddr")
252
- # uri.to_mailtext
253
- # # => "To: ruby-list@ruby-lang.org\nSubject: subscribe\nCc: myaddr\n\n\n"
254
- #
255
- def to_mailtext
256
- to = parser.unescape(@to)
257
- head = ''
258
- body = ''
259
- @headers.each do |x|
260
- case x[0]
261
- when 'body'
262
- body = parser.unescape(x[1])
263
- when 'to'
264
- to << ', ' + parser.unescape(x[1])
265
- else
266
- head << parser.unescape(x[0]).capitalize + ': ' +
267
- parser.unescape(x[1]) + "\n"
268
- end
269
- end
270
-
271
- return "To: #{to}
272
- #{head}
273
- #{body}
274
- "
275
- end
276
- alias to_rfc822text to_mailtext
277
- end
278
-
279
- @@schemes['MAILTO'] = MailTo
280
- end