opal 0.3.11 → 0.3.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (282) hide show
  1. data/.gitignore +13 -0
  2. data/Gemfile +10 -0
  3. data/LICENSE +20 -0
  4. data/README.md +11 -116
  5. data/Rakefile +126 -0
  6. data/bin/opal +1 -2
  7. data/docs/spec_runner.html +16 -0
  8. data/index.html +434 -0
  9. data/lib/opal.rb +14 -15
  10. data/lib/opal/builder.rb +46 -148
  11. data/lib/opal/command.rb +45 -115
  12. data/lib/opal/context.rb +139 -78
  13. data/lib/opal/dependency_builder.rb +34 -0
  14. data/lib/opal/environment.rb +92 -0
  15. data/lib/opal/parser/grammar.rb +4915 -0
  16. data/lib/opal/{parser.y → parser/grammar.y} +430 -284
  17. data/lib/opal/parser/lexer.rb +1329 -0
  18. data/lib/opal/parser/parser.rb +1460 -0
  19. data/lib/opal/parser/scope.rb +140 -0
  20. data/lib/opal/parser/sexp.rb +17 -0
  21. data/lib/opal/version.rb +2 -1
  22. data/opal.gemspec +23 -0
  23. data/opal.js +3149 -4162
  24. data/runtime/README.md +25 -0
  25. data/runtime/corelib/alpha.rb +10 -0
  26. data/runtime/corelib/array.rb +962 -0
  27. data/runtime/corelib/basic_object.rb +66 -0
  28. data/runtime/corelib/boolean.rb +44 -0
  29. data/runtime/corelib/class.rb +43 -0
  30. data/runtime/corelib/comparable.rb +25 -0
  31. data/runtime/corelib/complex.rb +2 -0
  32. data/runtime/corelib/dir.rb +29 -0
  33. data/runtime/corelib/enumerable.rb +316 -0
  34. data/runtime/corelib/enumerator.rb +80 -0
  35. data/runtime/corelib/error.rb +25 -0
  36. data/runtime/corelib/file.rb +80 -0
  37. data/runtime/corelib/hash.rb +503 -0
  38. data/runtime/corelib/io.rb +44 -0
  39. data/runtime/corelib/kernel.rb +237 -0
  40. data/runtime/corelib/load_order +29 -0
  41. data/runtime/corelib/match_data.rb +37 -0
  42. data/runtime/corelib/module.rb +171 -0
  43. data/runtime/corelib/native.rb +50 -0
  44. data/runtime/corelib/nil_class.rb +47 -0
  45. data/runtime/corelib/numeric.rb +219 -0
  46. data/runtime/corelib/object.rb +21 -0
  47. data/runtime/corelib/proc.rb +42 -0
  48. data/runtime/corelib/range.rb +38 -0
  49. data/runtime/corelib/rational.rb +16 -0
  50. data/runtime/corelib/regexp.rb +63 -0
  51. data/runtime/corelib/string.rb +185 -0
  52. data/runtime/corelib/struct.rb +97 -0
  53. data/runtime/corelib/time.rb +196 -0
  54. data/runtime/corelib/top_self.rb +7 -0
  55. data/runtime/gemlib/alpha.rb +5 -0
  56. data/runtime/gemlib/kernel.rb +17 -0
  57. data/runtime/gemlib/load_order +2 -0
  58. data/runtime/kernel/class.js +256 -0
  59. data/runtime/kernel/debug.js +42 -0
  60. data/runtime/kernel/init.js +114 -0
  61. data/runtime/kernel/load_order +5 -0
  62. data/runtime/kernel/loader.js +151 -0
  63. data/runtime/kernel/runtime.js +414 -0
  64. data/runtime/spec/README.md +34 -0
  65. data/runtime/spec/core/array/allocate_spec.rb +15 -0
  66. data/runtime/spec/core/array/append_spec.rb +31 -0
  67. data/runtime/spec/core/array/assoc_spec.rb +29 -0
  68. data/runtime/spec/core/array/at_spec.rb +38 -0
  69. data/runtime/spec/core/array/clear_spec.rb +22 -0
  70. data/runtime/spec/core/array/collect_spec.rb +3 -0
  71. data/runtime/spec/core/array/compact_spec.rb +42 -0
  72. data/runtime/spec/core/array/concat_spec.rb +21 -0
  73. data/runtime/spec/core/array/constructor_spec.rb +24 -0
  74. data/runtime/spec/core/array/count_spec.rb +11 -0
  75. data/runtime/spec/core/array/delete_at_spec.rb +31 -0
  76. data/runtime/spec/core/array/delete_if_spec.rb +24 -0
  77. data/runtime/spec/core/array/delete_spec.rb +26 -0
  78. data/runtime/spec/core/array/each_index_spec.rb +33 -0
  79. data/runtime/spec/core/array/each_spec.rb +11 -0
  80. data/runtime/spec/core/array/element_reference_spec.rb +136 -0
  81. data/runtime/spec/core/array/element_set_spec.rb +7 -0
  82. data/runtime/spec/core/array/empty_spec.rb +10 -0
  83. data/runtime/spec/core/array/eql_spec.rb +3 -0
  84. data/runtime/spec/core/array/equal_value_spec.rb +3 -0
  85. data/runtime/spec/core/array/fetch_spec.rb +26 -0
  86. data/runtime/spec/core/array/first_spec.rb +54 -0
  87. data/runtime/spec/core/array/fixtures/classes.rb +8 -0
  88. data/runtime/spec/core/array/flatten_spec.rb +41 -0
  89. data/runtime/spec/core/array/include_spec.rb +20 -0
  90. data/runtime/spec/core/array/insert_spec.rb +59 -0
  91. data/runtime/spec/core/array/last_spec.rb +57 -0
  92. data/runtime/spec/core/array/length_spec.rb +3 -0
  93. data/runtime/spec/core/array/map_spec.rb +3 -0
  94. data/runtime/spec/core/array/plus_spec.rb +16 -0
  95. data/runtime/spec/core/array/pop_spec.rb +79 -0
  96. data/runtime/spec/core/array/push_spec.rb +19 -0
  97. data/runtime/spec/core/array/rassoc_spec.rb +12 -0
  98. data/runtime/spec/core/array/reject_spec.rb +54 -0
  99. data/runtime/spec/core/array/replace_spec.rb +3 -0
  100. data/runtime/spec/core/array/reverse_each_spec.rb +18 -0
  101. data/runtime/spec/core/array/reverse_spec.rb +9 -0
  102. data/runtime/spec/core/array/shared/collect.rb +53 -0
  103. data/runtime/spec/core/array/shared/eql.rb +19 -0
  104. data/runtime/spec/core/array/shared/length.rb +6 -0
  105. data/runtime/spec/core/array/shared/replace.rb +31 -0
  106. data/runtime/spec/core/class/new_spec.rb +19 -0
  107. data/runtime/spec/core/enumerable/all_spec.rb +102 -0
  108. data/runtime/spec/core/enumerable/any_spec.rb +115 -0
  109. data/runtime/spec/core/enumerable/collect_spec.rb +3 -0
  110. data/runtime/spec/core/enumerable/count_spec.rb +29 -0
  111. data/runtime/spec/core/enumerable/detect_spec.rb +3 -0
  112. data/runtime/spec/core/enumerable/find_spec.rb +3 -0
  113. data/runtime/spec/core/enumerable/fixtures/classes.rb +26 -0
  114. data/runtime/spec/core/enumerable/shared/collect.rb +12 -0
  115. data/runtime/spec/core/enumerable/shared/entries.rb +7 -0
  116. data/runtime/spec/core/enumerable/shared/find.rb +49 -0
  117. data/runtime/spec/core/enumerable/to_a_spec.rb +7 -0
  118. data/runtime/spec/core/false/and_spec.rb +11 -0
  119. data/runtime/spec/core/false/inspect_spec.rb +7 -0
  120. data/runtime/spec/core/false/or_spec.rb +11 -0
  121. data/runtime/spec/core/false/to_s_spec.rb +7 -0
  122. data/runtime/spec/core/false/xor_spec.rb +11 -0
  123. data/runtime/spec/core/hash/allocate_spec.rb +15 -0
  124. data/runtime/spec/core/hash/assoc_spec.rb +29 -0
  125. data/runtime/spec/core/hash/clear_spec.rb +21 -0
  126. data/runtime/spec/core/hash/clone_spec.rb +12 -0
  127. data/runtime/spec/core/hash/default_spec.rb +6 -0
  128. data/runtime/spec/core/hash/delete_if_spec.rb +15 -0
  129. data/runtime/spec/core/hash/element_reference_spec.rb +16 -0
  130. data/runtime/spec/core/hash/element_set_spec.rb +8 -0
  131. data/runtime/spec/core/hash/new_spec.rb +13 -0
  132. data/runtime/spec/core/matchdata/to_a_spec.rb +7 -0
  133. data/runtime/spec/core/nil/and_spec.rb +12 -0
  134. data/runtime/spec/core/nil/inspect_spec.rb +8 -0
  135. data/runtime/spec/core/nil/nil_spec.rb +8 -0
  136. data/runtime/spec/core/nil/or_spec.rb +12 -0
  137. data/runtime/spec/core/nil/to_a_spec.rb +8 -0
  138. data/runtime/spec/core/nil/to_f_spec.rb +12 -0
  139. data/runtime/spec/core/nil/to_i_spec.rb +12 -0
  140. data/runtime/spec/core/nil/to_s_spec.rb +8 -0
  141. data/runtime/spec/core/nil/xor_spec.rb +12 -0
  142. data/runtime/spec/core/numeric/equal_value_spec.rb +11 -0
  143. data/runtime/spec/core/object/is_a_spec.rb +2 -0
  144. data/runtime/spec/core/object/shared/kind_of.rb +0 -0
  145. data/runtime/spec/core/regexp/match_spec.rb +23 -0
  146. data/runtime/spec/core/regexp/shared/match.rb +11 -0
  147. data/runtime/spec/core/symbol/to_proc_spec.rb +8 -0
  148. data/runtime/spec/core/true/and_spec.rb +11 -0
  149. data/runtime/spec/core/true/inspect_spec.rb +7 -0
  150. data/runtime/spec/core/true/or_spec.rb +11 -0
  151. data/runtime/spec/core/true/to_s_spec.rb +7 -0
  152. data/runtime/spec/core/true/xor_spec.rb +11 -0
  153. data/runtime/spec/language/alias_spec.rb +25 -0
  154. data/runtime/spec/language/and_spec.rb +62 -0
  155. data/runtime/spec/language/array_spec.rb +68 -0
  156. data/runtime/spec/language/block_spec.rb +105 -0
  157. data/runtime/spec/language/break_spec.rb +49 -0
  158. data/runtime/spec/language/case_spec.rb +165 -0
  159. data/runtime/spec/language/defined_spec.rb +80 -0
  160. data/runtime/spec/language/ensure_spec.rb +82 -0
  161. data/runtime/spec/language/fixtures/block.rb +19 -0
  162. data/runtime/spec/language/fixtures/break.rb +39 -0
  163. data/runtime/spec/language/fixtures/defined.rb +9 -0
  164. data/runtime/spec/language/fixtures/ensure.rb +37 -0
  165. data/runtime/spec/language/fixtures/next.rb +46 -0
  166. data/runtime/spec/language/fixtures/send.rb +36 -0
  167. data/runtime/spec/language/fixtures/super.rb +43 -0
  168. data/runtime/spec/language/hash_spec.rb +43 -0
  169. data/runtime/spec/language/if_spec.rb +278 -0
  170. data/runtime/spec/language/loop_spec.rb +32 -0
  171. data/runtime/spec/language/next_spec.rb +128 -0
  172. data/runtime/spec/language/or_spec.rb +65 -0
  173. data/runtime/spec/language/predefined_spec.rb +21 -0
  174. data/runtime/spec/language/regexp/interpolation_spec.rb +9 -0
  175. data/runtime/spec/language/regexp_spec.rb +7 -0
  176. data/runtime/spec/language/send_spec.rb +105 -0
  177. data/runtime/spec/language/string_spec.rb +4 -0
  178. data/runtime/spec/language/super_spec.rb +18 -0
  179. data/runtime/spec/language/symbol_spec.rb +41 -0
  180. data/runtime/spec/language/undef_spec.rb +16 -0
  181. data/runtime/spec/language/unless_spec.rb +44 -0
  182. data/runtime/spec/language/until_spec.rb +137 -0
  183. data/runtime/spec/language/variables_spec.rb +28 -0
  184. data/runtime/spec/language/versions/hash_1.9.rb +20 -0
  185. data/runtime/spec/language/while_spec.rb +175 -0
  186. data/runtime/spec/library/stringscanner/scan_spec.rb +36 -0
  187. data/runtime/spec/opal/forwardable/def_instance_delegator_spec.rb +49 -0
  188. data/runtime/spec/opal/opal/defined_spec.rb +15 -0
  189. data/runtime/spec/opal/opal/function_spec.rb +11 -0
  190. data/runtime/spec/opal/opal/native_spec.rb +16 -0
  191. data/runtime/spec/opal/opal/null_spec.rb +10 -0
  192. data/runtime/spec/opal/opal/number_spec.rb +11 -0
  193. data/runtime/spec/opal/opal/object_spec.rb +16 -0
  194. data/runtime/spec/opal/opal/string_spec.rb +11 -0
  195. data/runtime/spec/opal/opal/typeof_spec.rb +9 -0
  196. data/runtime/spec/opal/opal/undefined_spec.rb +10 -0
  197. data/runtime/spec/opal/true/case_compare_spec.rb +12 -0
  198. data/runtime/spec/opal/true/class_spec.rb +10 -0
  199. data/runtime/spec/spec_helper.rb +25 -0
  200. data/runtime/stdlib/base64.rb +91 -0
  201. data/runtime/stdlib/date.rb +4 -0
  202. data/{stdlib → runtime/stdlib}/dev.rb +0 -0
  203. data/runtime/stdlib/forwardable.rb +33 -0
  204. data/runtime/stdlib/optparse.rb +0 -0
  205. data/runtime/stdlib/pp.rb +6 -0
  206. data/{stdlib → runtime/stdlib}/racc/parser.rb +0 -0
  207. data/runtime/stdlib/rbconfig.rb +0 -0
  208. data/runtime/stdlib/si.rb +17 -0
  209. data/runtime/stdlib/strscan.rb +53 -0
  210. data/runtime/stdlib/uri.rb +111 -0
  211. data/runtime/stdlib/uri/common.rb +1014 -0
  212. data/runtime/stdlib/uri/ftp.rb +261 -0
  213. data/runtime/stdlib/uri/generic.rb +1599 -0
  214. data/runtime/stdlib/uri/http.rb +106 -0
  215. data/runtime/stdlib/uri/https.rb +22 -0
  216. data/runtime/stdlib/uri/ldap.rb +260 -0
  217. data/runtime/stdlib/uri/ldaps.rb +20 -0
  218. data/runtime/stdlib/uri/mailto.rb +280 -0
  219. data/spec/builder/build_source_spec.rb +52 -0
  220. data/spec/builder/fixtures/build_source/adam.rb +0 -0
  221. data/spec/builder/fixtures/build_source/bar/a.rb +0 -0
  222. data/spec/builder/fixtures/build_source/bar/wow/b.rb +0 -0
  223. data/spec/builder/fixtures/build_source/bar/wow/cow/c.rb +0 -0
  224. data/spec/builder/fixtures/build_source/beynon.rb +0 -0
  225. data/spec/builder/fixtures/build_source/charles.js +0 -0
  226. data/spec/builder/fixtures/build_source/foo/a.rb +0 -0
  227. data/spec/builder/fixtures/build_source/foo/b.rb +0 -0
  228. data/spec/builder/fixtures/build_source/foo/x.js +0 -0
  229. data/spec/builder/fixtures/build_source/foo/y.js +0 -0
  230. data/spec/builder/output_path_spec.rb +50 -0
  231. data/spec/grammar/alias_spec.rb +26 -0
  232. data/spec/grammar/and_spec.rb +13 -0
  233. data/spec/grammar/array_spec.rb +22 -0
  234. data/spec/grammar/attrasgn_spec.rb +28 -0
  235. data/spec/grammar/begin_spec.rb +38 -0
  236. data/spec/grammar/block_spec.rb +12 -0
  237. data/spec/grammar/break_spec.rb +17 -0
  238. data/spec/grammar/call_spec.rb +58 -0
  239. data/spec/grammar/class_spec.rb +35 -0
  240. data/spec/grammar/const_spec.rb +13 -0
  241. data/spec/grammar/cvar_spec.rb +11 -0
  242. data/spec/grammar/def_spec.rb +60 -0
  243. data/spec/grammar/false_spec.rb +17 -0
  244. data/spec/grammar/file_spec.rb +7 -0
  245. data/spec/grammar/gvar_spec.rb +13 -0
  246. data/spec/grammar/hash_spec.rb +17 -0
  247. data/spec/grammar/iasgn_spec.rb +9 -0
  248. data/spec/grammar/if_spec.rb +26 -0
  249. data/spec/grammar/iter_spec.rb +59 -0
  250. data/spec/grammar/ivar_spec.rb +9 -0
  251. data/spec/grammar/lasgn_spec.rb +8 -0
  252. data/spec/grammar/line_spec.rb +8 -0
  253. data/spec/grammar/lvar_spec.rb +38 -0
  254. data/spec/grammar/module_spec.rb +27 -0
  255. data/spec/grammar/nil_spec.rb +17 -0
  256. data/spec/grammar/not_spec.rb +27 -0
  257. data/spec/grammar/op_asgn1_spec.rb +23 -0
  258. data/spec/grammar/op_asgn2_spec.rb +23 -0
  259. data/spec/grammar/or_spec.rb +13 -0
  260. data/spec/grammar/return_spec.rb +17 -0
  261. data/spec/grammar/sclass_spec.rb +20 -0
  262. data/spec/grammar/self_spec.rb +17 -0
  263. data/spec/grammar/str_spec.rb +96 -0
  264. data/spec/grammar/super_spec.rb +20 -0
  265. data/spec/grammar/true_spec.rb +17 -0
  266. data/spec/grammar/undef_spec.rb +15 -0
  267. data/spec/grammar/unless_spec.rb +13 -0
  268. data/spec/grammar/while_spec.rb +15 -0
  269. data/spec/grammar/xstr_spec.rb +116 -0
  270. data/spec/grammar/yield_spec.rb +20 -0
  271. data/spec/spec_helper.rb +9 -0
  272. metadata +346 -21
  273. data/lib/opal/bundle.rb +0 -34
  274. data/lib/opal/lexer.rb +0 -902
  275. data/lib/opal/nodes.rb +0 -2150
  276. data/lib/opal/parser.rb +0 -4894
  277. data/lib/opal/rake/bundle_task.rb +0 -63
  278. data/opal-parser.js +0 -8343
  279. data/stdlib/strscan.rb +0 -52
  280. data/templates/init/Rakefile +0 -7
  281. data/templates/init/index.html +0 -17
  282. data/templates/init/lib/__NAME__.rb +0 -2
@@ -0,0 +1,106 @@
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
@@ -0,0 +1,22 @@
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
@@ -0,0 +1,260 @@
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
@@ -0,0 +1,20 @@
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
@@ -0,0 +1,280 @@
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