sleipnir-api 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. data/History.txt +3 -0
  2. data/License.txt +20 -0
  3. data/Manifest.txt +41 -0
  4. data/README.txt +56 -0
  5. data/Rakefile +201 -0
  6. data/TODO.txt +11 -0
  7. data/examples/reload.rb +18 -0
  8. data/helper/helper.rb +3 -0
  9. data/helper/rake.rb +58 -0
  10. data/helper/rake_sh_filter.rb +23 -0
  11. data/helper/util.rb +19 -0
  12. data/lib/sleipnir_api.rb +177 -0
  13. data/lib/sleipnir_api/dialog.rb +155 -0
  14. data/lib/sleipnir_api/key_state.rb +49 -0
  15. data/lib/sleipnir_api/output.rb +319 -0
  16. data/lib/sleipnir_api/process.rb +69 -0
  17. data/lib/sleipnir_api/profile.rb +332 -0
  18. data/lib/sleipnir_api/registry.rb +30 -0
  19. data/lib/sleipnir_api/security.rb +263 -0
  20. data/lib/sleipnir_api/sleipnir.rb +489 -0
  21. data/lib/sleipnir_api/tab.rb +359 -0
  22. data/lib/sleipnir_api/util.rb +16 -0
  23. data/lib/sleipnir_api/version.rb +9 -0
  24. data/lib/sleipnir_api/win32api.rb +17 -0
  25. data/scripts/rdoc_filter.rb +74 -0
  26. data/setup.rb +1585 -0
  27. data/spec/matchers/path_eql.rb +41 -0
  28. data/spec/sleipnir_api/dialog_mock_spec.rb +99 -0
  29. data/spec/sleipnir_api/key_state_mock_spec.rb +72 -0
  30. data/spec/sleipnir_api/output_spec.rb +242 -0
  31. data/spec/sleipnir_api/profile_mock_spec.rb +128 -0
  32. data/spec/sleipnir_api/registry_spec.rb +13 -0
  33. data/spec/sleipnir_api/security_mock_spec.rb +82 -0
  34. data/spec/sleipnir_api/security_spec.rb +129 -0
  35. data/spec/sleipnir_api/sleipnir_mock_spec.rb +70 -0
  36. data/spec/sleipnir_api/sleipnir_spec.rb +295 -0
  37. data/spec/sleipnir_api/tab_mock_spec.rb +98 -0
  38. data/spec/sleipnir_api/tab_spec.rb +105 -0
  39. data/spec/sleipnir_api_spec.rb +17 -0
  40. data/spec/spec.opts +0 -0
  41. data/spec/spec_helper.rb +8 -0
  42. metadata +91 -0
@@ -0,0 +1,3 @@
1
+ == 0.1.0 / 2007-07-22
2
+
3
+ * Initial beta release
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2007 MIYAMUKO Katsuyuki <mailto:miyamuko@gmail.com>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,41 @@
1
+ History.txt
2
+ License.txt
3
+ Manifest.txt
4
+ README.txt
5
+ Rakefile
6
+ TODO.txt
7
+ examples/reload.rb
8
+ helper/helper.rb
9
+ helper/rake.rb
10
+ helper/rake_sh_filter.rb
11
+ helper/util.rb
12
+ lib/sleipnir_api.rb
13
+ lib/sleipnir_api/dialog.rb
14
+ lib/sleipnir_api/key_state.rb
15
+ lib/sleipnir_api/output.rb
16
+ lib/sleipnir_api/process.rb
17
+ lib/sleipnir_api/profile.rb
18
+ lib/sleipnir_api/registry.rb
19
+ lib/sleipnir_api/security.rb
20
+ lib/sleipnir_api/sleipnir.rb
21
+ lib/sleipnir_api/tab.rb
22
+ lib/sleipnir_api/util.rb
23
+ lib/sleipnir_api/version.rb
24
+ lib/sleipnir_api/win32api.rb
25
+ scripts/rdoc_filter.rb
26
+ setup.rb
27
+ spec/matchers/path_eql.rb
28
+ spec/sleipnir_api/dialog_mock_spec.rb
29
+ spec/sleipnir_api/key_state_mock_spec.rb
30
+ spec/sleipnir_api/output_spec.rb
31
+ spec/sleipnir_api/profile_mock_spec.rb
32
+ spec/sleipnir_api/registry_spec.rb
33
+ spec/sleipnir_api/security_mock_spec.rb
34
+ spec/sleipnir_api/security_spec.rb
35
+ spec/sleipnir_api/sleipnir_mock_spec.rb
36
+ spec/sleipnir_api/sleipnir_spec.rb
37
+ spec/sleipnir_api/tab_mock_spec.rb
38
+ spec/sleipnir_api/tab_spec.rb
39
+ spec/sleipnir_api_spec.rb
40
+ spec/spec.opts
41
+ spec/spec_helper.rb
@@ -0,0 +1,56 @@
1
+ == sleipnir-api - Sleipnir.API の Ruby Interface
2
+
3
+ === DESCRIPTION
4
+
5
+ sleipnir-api は {Sleipnir}[http://www.fenrir.co.jp/sleipnir2-the-world/] の
6
+ COM サーバ (Sleipnir.API) を操作するための Ruby ライブラリです。
7
+
8
+ WIN32OLE オブジェクトをラップし、Ruby らしいインターフェイスを提供します。
9
+
10
+ API 仕様は SleipnirAPI を参照してください。
11
+
12
+
13
+ === SYNOPSIS
14
+
15
+ require "rubygems"
16
+ require "sleipnir_api"
17
+
18
+ SleipnirAPI.new do |pnir|
19
+ pnir.each do |tab|
20
+ if tab.location.href =~ /workspace/
21
+ tab.location.reload
22
+ end
23
+ end
24
+ end
25
+
26
+
27
+ === INSTALL
28
+
29
+ [Unix]
30
+ sudo gem install sleipnir-api
31
+
32
+ [Windows]
33
+ gem install sleipnir-api
34
+
35
+
36
+ === CAVEATS
37
+
38
+ * Sleipnir 2.xx オリジナルの動作と違う部分があります。
39
+ 詳細は SleipnirAPI の「非互換性」を参照してください。
40
+
41
+ * Sleipnir 2.xx でのテストはあまりしていません。
42
+
43
+ === COPYRIGHT
44
+
45
+ Copyright (c) 2007 MIYAMUKO Katsuyuki.
46
+
47
+ sleipnir-api is released under an MIT license.
48
+ See {License.txt}[link:files/License_txt.html] for full license.
49
+
50
+
51
+ === OTHER STUFF
52
+
53
+ Author:: MIYAMUKO Katsuyuki <mailto:miyamuko@gmail.com>
54
+ Home URL:: http://sleipnir-api.rubyforge.org
55
+ Project URL:: http://rubyforge.org/projects/sleipnir-api
56
+ Blog (Japanese):: {id:miyamuko}[http://d.hatena.ne.jp/miyamuko/]
@@ -0,0 +1,201 @@
1
+ # -*- mode: ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'rake'
5
+ require 'rake/clean'
6
+ require 'rake/testtask'
7
+ require 'rake/packagetask'
8
+ require 'rake/gempackagetask'
9
+ require 'rake/rdoctask'
10
+ require 'rake/contrib/rubyforgepublisher'
11
+ require 'fileutils'
12
+ require 'hoe'
13
+ begin
14
+ require 'spec/rake/spectask'
15
+ rescue LoadError
16
+ puts 'To use rspec for testing you must install rspec gem:'
17
+ puts '$ sudo gem install rspec'
18
+ exit
19
+ end
20
+
21
+ require 'helper/helper'
22
+
23
+ include FileUtils
24
+ require File.join(File.dirname(__FILE__), 'lib', 'sleipnir_api', 'version')
25
+
26
+ AUTHOR = 'MIYAMUKO Katsuyuki' # can also be an array of Authors
27
+ EMAIL = "miyamuko@gmail.com"
28
+ DESCRIPTION = "Ruby interface to the Sleipnir COM API"
29
+ GEM_NAME = 'sleipnir-api' # what ppl will type to install your gem
30
+ RDOC_DIR = "./html"
31
+ NEWS_FILE = "news.txt"
32
+
33
+ @config_file = "~/.rubyforge/user-config.yml"
34
+ @config = nil
35
+ def rubyforge_username
36
+ unless @config
37
+ begin
38
+ @config = YAML.load(File.read(File.expand_path(@config_file)))
39
+ rescue
40
+ puts "ERROR: No rubyforge config file found: #{@config_file}"
41
+ puts "Run 'rubyforge setup' to prepare your env for access to Rubyforge"
42
+ exit
43
+ end
44
+ end
45
+ @rubyforge_username ||= @config["username"]
46
+ end
47
+
48
+ RUBYFORGE_PROJECT = 'sleipnir-api' # The unix name for your project
49
+ HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
50
+ DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
51
+
52
+ NAME = "sleipnir-api"
53
+ REV = nil
54
+ # UNCOMMENT IF REQUIRED:
55
+ # REV = `svn info`.each {|line| if line =~ /^Revision:/ then k,v = line.split(': '); break v.chomp; else next; end} rescue nil
56
+ VERS = SleipnirAPI::VERSION::STRING + (REV ? ".#{REV}" : "")
57
+ CLEAN.include ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store', NEWS_FILE]
58
+
59
+
60
+ class Hoe
61
+ def extra_deps
62
+ @extra_deps.reject!{|x| Array(x).first == 'hoe' }
63
+ @extra_deps
64
+ end
65
+ end
66
+
67
+ # Generate all the Rake tasks
68
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
69
+ hoe = Hoe.new(GEM_NAME, VERS) do |p|
70
+ p.author = AUTHOR
71
+ p.email = EMAIL
72
+ p.url = HOMEPATH
73
+
74
+ p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
75
+ p.test_globs = []
76
+ p.clean_globs |= CLEAN #An array of file patterns to delete on clean.
77
+
78
+ p.description = p.summary = "Ruby interface to the Sleipnir.API WIN32OLE object."
79
+ p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
80
+
81
+ p.need_zip = true
82
+ p.need_tar = true
83
+ end
84
+
85
+ desc 'Release the website and new gem version'
86
+ task :deploy => [:check_manifest!, :check_version, :publish_docs, :release]
87
+
88
+ task :check_manifest! => [:check_manifest] do
89
+ unless $?.success?
90
+ puts "----"
91
+ puts "Please update Manifest.txt."
92
+ exit 1
93
+ end
94
+ end
95
+
96
+ task :check_version do
97
+ unless ENV['VERSION']
98
+ puts 'Must pass a VERSION=x.y.z release version'
99
+ exit
100
+ end
101
+ unless ENV['VERSION'] == VERS
102
+ puts "Please update your version.rb to match the release version, currently #{VERS}"
103
+ exit
104
+ end
105
+ histver = File.read("History.txt")[/^== (\d+\.\d+\.\d+)/, 1]
106
+ unless ENV['VERSION'] == histver
107
+ puts "Please update your History.txt to match the release version, currently #{histver}"
108
+ exit
109
+ end
110
+ end
111
+
112
+ # remove :test task defined by Hoe.
113
+ remove_tasks :test, :test_deps, :default
114
+
115
+ desc "Run the specs under spec/models"
116
+ Spec::Rake::SpecTask.new do |t|
117
+ t.spec_opts = ['--options', "spec/spec.opts"]
118
+ t.spec_files = FileList['spec/**/*_spec.rb']
119
+ end
120
+ task :test => [:spec]
121
+
122
+ desc "Default task is to run specs"
123
+ task :default => :spec
124
+
125
+ #
126
+ # new task
127
+ #
128
+
129
+ desc 'Uninstall the gem package'
130
+ task_for_windows :uninstall_gem do
131
+ sh "gem.bat uninstall #{ENV['GEMOPTS']} #{GEM_NAME}"
132
+ end
133
+
134
+
135
+ #
136
+ # overwrite hoe defined tasks.
137
+ #
138
+
139
+ remove_tasks(:clobber_docs, :docs, :redocs)
140
+ Rake::RDocTask.new(:docs) do |rd|
141
+ rd.main = "README.txt"
142
+ rd.rdoc_dir = RDOC_DIR
143
+ files = File.read("Manifest.txt").split.grep(/^(lib|bin)|txt$/)
144
+ files -= ['Manifest.txt']
145
+ rd.rdoc_files.push(*files)
146
+
147
+ rd.options << "-t #{NAME}-#{VERS} Documentation"
148
+ rd.options << '--charset=UTF-8'
149
+ end
150
+
151
+ # remove HTML comment and so on.
152
+ task :docs do
153
+ ruby "scripts/rdoc_filter.rb #{RDOC_DIR}/**/*.html"
154
+ end
155
+
156
+
157
+ task_for_windows :install_gem do
158
+ sh "gem.bat install #{ENV['GEMOPTS']} pkg/*.gem"
159
+ end
160
+
161
+ task_for_windows :ridocs do
162
+ sh "rdoc.bat --ri -o ri ."
163
+ end
164
+
165
+ task_for_windows :publish_docs do
166
+ Rake::RubyForgePublisher.new(RUBYFORGE_PROJECT, @rubyforge_username).upload
167
+ end
168
+
169
+ # rake publish_docs SCP=pscp
170
+ if ENV["SCP"] and ENV["SCP"] != "scp"
171
+ add_sh_filter_for(/\Ascp /) {|cmd|
172
+ cmd[0].sub!(/\Ascp/, ENV["SCP"])
173
+ cmd[0].sub!(/-rq/, "-r")
174
+ cmd
175
+ }
176
+ end
177
+
178
+
179
+ task :create_news do
180
+ subject, title, body, urls = hoe.announcement
181
+ open(NEWS_FILE, "w") do |w|
182
+ w.puts subject
183
+ w.puts "#{title}\n\n#{body}\n\n"
184
+ w.puts "--"
185
+ w.puts "Home URL: #{HOMEPATH}"
186
+ w.puts "Project URL: #{DOWNLOAD_PATH}"
187
+ end
188
+ puts File.read(NEWS_FILE)
189
+ end
190
+
191
+ override_task :post_news do
192
+ subject, body = File.read(NEWS_FILE).split(/\n/, 2)
193
+ require 'rubyforge'
194
+ rf = RubyForge.new
195
+ rf.login
196
+ rf.post_news(RUBYFORGE_PROJECT, subject, body)
197
+ puts "Posted to rubyforge `#{subject}'."
198
+ rm_f NEWS_FILE
199
+ end
200
+
201
+ # vim: syntax=Ruby
@@ -0,0 +1,11 @@
1
+ == TODO
2
+
3
+ * Sleipnir の起動・終了を WMI を使わずに実装。
4
+ * Sleipnir の終了時に Window Handle をちゃんと見る。
5
+ * grepnir
6
+ * example
7
+ * ExecCommand
8
+ * コマンドの一覧
9
+ * Sleipnir 2.x のサポート
10
+ * ExecAction とか
11
+
@@ -0,0 +1,18 @@
1
+ $LOAD_PATH << File.join(File.dirname(__FILE__), "../lib")
2
+ require "sleipnir_api"
3
+
4
+ if ARGV.empty?
5
+ puts "Usage: #{$0} REGEXP..."
6
+ exit 1
7
+ end
8
+
9
+ regexp = ARGV.map {|arg| Regexp.compile(arg) rescue Regexp.compile(Regexp.quote(arg)) }
10
+
11
+ SleipnirAPI.new do |pnir|
12
+ pnir.each do |tab|
13
+ if regexp.any? {|re| re.match(tab.location.href) }
14
+ puts tab.location.href
15
+ tab.location.reload
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ require "helper/util"
2
+ require "helper/rake"
3
+ require "helper/rake_sh_filter"
@@ -0,0 +1,58 @@
1
+ require "rubygems"
2
+ require "rake"
3
+
4
+ def tasks
5
+ Rake.application.instance_eval { @tasks }
6
+ end
7
+
8
+ def current_scope
9
+ Rake.application.instance_eval { @scope.last }
10
+ end
11
+
12
+ def task_defined?(task_name)
13
+ Rake::Task.task_defined?(task_name)
14
+ end
15
+
16
+ def remove_tasks(*task_names)
17
+ task_names.flatten.each do |task_name|
18
+ remove_task(task_name)
19
+ end
20
+ end
21
+
22
+ def remove_task(task_name)
23
+ tasks.delete(task_name.to_s)
24
+ end
25
+
26
+ def lookup_task(task_name)
27
+ Rake::Task[task_name] rescue nil
28
+ end
29
+
30
+ def rakecall(task_name)
31
+ lookup_task(task_name).invoke
32
+ end
33
+
34
+ def override_task(task_args, &block)
35
+ task_name, deps = Rake.application.resolve_args(task_args)
36
+ original = lookup_task(task_name)
37
+ orgproc = lambda {} # nop
38
+ if original
39
+ Rake.application.last_comment = original.comment
40
+ deps |= original.prerequisites
41
+ orgproc = lambda{ original.execute }
42
+ end
43
+
44
+ remove_task(task_name)
45
+ Rake::Task.define_task(task_name => deps) do |t|
46
+ block.call(t, orgproc)
47
+ end
48
+ end
49
+
50
+ def task_for_windows(task_args, &block)
51
+ override_task(task_args) do |t, org|
52
+ if windows?
53
+ block.call(t)
54
+ else
55
+ org.call
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,23 @@
1
+ module FileUtils
2
+ SHELL_COMMAND_FILTER = []
3
+
4
+ alias sh_original sh
5
+ def sh(*cmd, &block)
6
+ cmd = SHELL_COMMAND_FILTER.inject(cmd){|c,filter| filter.call(c) or c }
7
+ sh_original(*cmd, &block)
8
+ end
9
+
10
+ def add_sh_filter(&block)
11
+ SHELL_COMMAND_FILTER << block
12
+ end
13
+
14
+ def add_sh_filter_for(pattern, &block)
15
+ add_sh_filter {|cmd|
16
+ if cmd[0] =~ pattern
17
+ block.call(cmd)
18
+ else
19
+ cmd
20
+ end
21
+ }
22
+ end
23
+ end