auto 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,35 +1,109 @@
1
- Automaton
2
- =========
1
+ Auto
2
+ ====
3
3
 
4
4
  Automate everything!
5
5
 
6
6
  Notice
7
7
  ------
8
8
 
9
- This gem is in development. Functionality updates will show up in this file.
9
+ This gem is currently under development. Some of what you see below is a fantasy.
10
10
 
11
- Goals
11
+ Install
12
+ -------
13
+
14
+ <pre>
15
+ sudo gem install auto --source http://gemcutter.org
16
+ </pre>
17
+
18
+ Introduction
19
+ ------------
20
+
21
+ Auto is a framework for writing automation scripts and plugins for those scripts.
22
+
23
+ <pre>
24
+ require 'rubygems'
25
+ require 'auto'
26
+
27
+ question :name => "What is your name?"
28
+ question :delete => "Delete file when finished? (y/n)"
29
+
30
+ file "#{@name}.txt" do |f|
31
+ f &lt;&lt; 'Append to text file'
32
+ f = 'Overwrite text file'
33
+ end
34
+
35
+ file("#{@name}.txt").delete if @delete
36
+ </pre>
37
+
38
+ Save it and run it like you would any other Ruby script.
39
+
40
+ In this example, <code>question</code> and <code>file</code> are both methods provided by the plugins <code>auto-question</code> and <code>auto-file</code>, respectively. They are included when you install the <code>auto</code> gem, but other plugins can be obtained via Rubygems.
41
+
42
+ Tasks
12
43
  -----
13
44
 
14
- * Writing automation scripts should be simple
15
- * Global namespace
16
- * A library of simple methods that do complex things
17
- * Adding outside scripts and script functionality should be simple
18
- * Obvious plugin structure
19
- * Automated installation/updates
20
- * Running tasks should be simple
21
- * Everything available via "auto task" command
22
- * Easy to ask questions
23
- * Sessions
24
- * Record input for any number of questions
25
- * Replay using "auto session" command
26
- * Or, use the web interface
27
- * Make it easy for novices to use and extend
45
+ Auto has a tasks system similar to Capistrano or Rake. In the previous example, if you had saved your script to <code>~/.auto/my/name.rb</code>, you would be able to run it by executing <code>auto my:name</code> in Terminal.
28
46
 
29
- Install
30
- -------
47
+ Tasks may also be included via plugin. See the **Authoring Plugins** section for more information.
48
+
49
+ Sessions
50
+ --------
51
+
52
+ Installing the <code>auto</code> gem also installs <code>auto-session</code>, which allows you to record the input to your Auto scripts and replay them later.
53
+
54
+ To save a session, run your script or task with the <code>SESSION</code> environment variable:
31
55
 
32
56
  <pre>
33
- gem sources -a http://gems.github.com
34
- sudo gem install winton-automaton
35
- </pre>
57
+ SESSION=name ruby my_name.rb
58
+ SESSION=name auto my:name
59
+ </pre>
60
+
61
+ This session would be saved in <code>~/.auto/session/name.rb</code> (run it by executing <code>auto session:name</code>). It might look like this:
62
+
63
+ <pre>
64
+ answer :name => 'Joe'
65
+ answer :delete => false
66
+ run 'my:name'
67
+ </pre>
68
+
69
+ The session script is executed as any other Auto script. This is cool because you can modify your session files to get custom input for certain questions.
70
+
71
+ <pre>
72
+ question :name => "What is your last name?"
73
+ answer :delete => false
74
+ run 'my:name'
75
+ </pre>
76
+
77
+ You also could have deleted the <code>:name</code> answer to ask that question upon running the session.
78
+
79
+ Authoring Plugins
80
+ -----------------
81
+
82
+ Plugins have a lib directory just like any other gem. Here is how the lib file for the Foo plugin might look:
83
+
84
+ <pre>
85
+ # lib/foo.rb
86
+ module Auto
87
+ module Foo
88
+
89
+ def foo(*args)
90
+ Foo.instance args
91
+ end
92
+
93
+ class Foo
94
+ class &lt;&lt;self
95
+
96
+ def instance(args)
97
+ # Do something
98
+ end
99
+ end
100
+ end
101
+ end
102
+ end
103
+ </pre>
104
+
105
+ Auto uses the gem name (<code>auto-foo</code>) to find <code>lib/foo.rb</code> and include <code>Auto::Foo</code> into the environment. Now you can call the <code>foo</code> method in any of your Auto scripts.
106
+
107
+ Auto plugins must have gem names with <code>auto-</code> as a prefix to be automatically required.
108
+
109
+ Include Auto tasks with your plugin by adding a <code>.auto</code> directory to your gem, just as you do with your home directory (<code>~/.auto</code>).
data/Rakefile CHANGED
@@ -2,28 +2,13 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'rake/gempackagetask'
4
4
  require 'spec/rake/spectask'
5
+ require 'gemspec'
5
6
 
6
- GEM_NAME = 'automaton'
7
- PKG_FILES = FileList['**/*'] - FileList['coverage', 'coverage/**/*', 'pkg', 'pkg/**/*']
8
-
9
- spec = Gem::Specification.new do |s|
10
- s.author = "Winton Welsh"
11
- s.email = "mail@wintoni.us"
12
- s.extra_rdoc_files = [ "README.markdown" ]
13
- s.files = PKG_FILES.to_a
14
- s.has_rdoc = false
15
- s.homepage = "http://github.com/winton/#{GEM_NAME}"
16
- s.name = 'auto'
17
- s.platform = Gem::Platform::RUBY
18
- s.require_path = "lib"
19
- s.summary = "Automate everything!"
20
- s.version = "0.1.0"
21
- end
22
-
23
-
24
- desc "Package gem"
25
- Rake::GemPackageTask.new(spec) do |pkg|
26
- pkg.gem_spec = spec
7
+ desc "Generate gemspec"
8
+ task :gemspec do
9
+ File.open("#{Dir.pwd}/#{GEM_NAME}.gemspec", 'w') do |f|
10
+ f.write(GEM_SPEC.to_ruby)
11
+ end
27
12
  end
28
13
 
29
14
  desc "Install gem"
@@ -34,10 +19,28 @@ task :install do
34
19
  `rm -Rf pkg`
35
20
  end
36
21
 
37
- desc "Generate gemspec"
38
- task :gemspec do
39
- File.open("#{File.dirname(__FILE__)}/#{GEM_NAME}.gemspec", 'w') do |f|
40
- f.write(spec.to_ruby)
22
+ desc "Package gem"
23
+ Rake::GemPackageTask.new(GEM_SPEC) do |pkg|
24
+ pkg.gem_spec = GEM_SPEC
25
+ end
26
+
27
+ desc "Rename project"
28
+ task :rename do
29
+ name = ENV['NAME'] || File.basename(Dir.pwd)
30
+ begin
31
+ dir = Dir['**/gem_template*']
32
+ from = dir.pop
33
+ if from
34
+ rb = from.include?('.rb')
35
+ to = File.dirname(from) + "/#{name}#{'.rb' if rb}"
36
+ FileUtils.mv(from, to)
37
+ end
38
+ end while dir.length > 0
39
+ Dir["**/*"].each do |path|
40
+ next if path.include?('Rakefile')
41
+ if File.file?(path)
42
+ `sed -i "" 's/gem_template/#{name}/g' #{path}`
43
+ end
41
44
  end
42
45
  end
43
46
 
@@ -0,0 +1,18 @@
1
+ GEM_NAME = 'auto'
2
+ GEM_FILES = FileList['**/*'] - FileList['coverage', 'coverage/**/*', 'pkg', 'pkg/**/*']
3
+ GEM_SPEC = Gem::Specification.new do |s|
4
+ # == CONFIGURE ==
5
+ s.author = "Winton Welsh"
6
+ s.email = "mail@wintoni.us"
7
+ s.homepage = "http://github.com/winton/#{GEM_NAME}"
8
+ s.summary = "Automate everything!"
9
+ # == CONFIGURE ==
10
+ s.add_dependency('auto-terminal', '=0.0.1')
11
+ s.extra_rdoc_files = [ "README.markdown" ]
12
+ s.files = GEM_FILES.to_a
13
+ s.has_rdoc = false
14
+ s.name = GEM_NAME
15
+ s.platform = Gem::Platform::RUBY
16
+ s.require_path = "lib"
17
+ s.version = "0.1.1"
18
+ end
@@ -0,0 +1,6 @@
1
+ require File.dirname(__FILE__) + "/auto/require"
2
+
3
+ module Auto
4
+ Runner.new { terminal($0) }
5
+ exit
6
+ end
File without changes
File without changes
@@ -1,6 +1,6 @@
1
1
  require 'rubygems'
2
2
 
3
- module Automaton
3
+ module Auto
4
4
  class Plugins
5
5
 
6
6
  @@directories = [
@@ -16,7 +16,7 @@ module Automaton
16
16
 
17
17
  # Add a directory to the plugin load paths.
18
18
  def add(path)
19
- @@directories = [] if $TESTING
19
+ @@directories = [] if $testing
20
20
  @@directories << path
21
21
  @@directories.uniq!
22
22
  @@plugins = nil
@@ -26,7 +26,7 @@ module Automaton
26
26
  def plugins
27
27
  return @@plugins if @@plugins
28
28
  directories = @@directories.collect do |d|
29
- File.expand_path("#{d}/*automaton-*/")
29
+ File.expand_path("#{d}/*auto-*/")
30
30
  end
31
31
  @@plugins = Dir[*directories].collect do |d|
32
32
  Plugin.new(d)
@@ -80,23 +80,23 @@ module Automaton
80
80
  name = File.basename(directory)
81
81
  name = name.split('-')
82
82
 
83
- return nil unless name.include?('automaton')
84
- @name = name[name.index('automaton') + 1]
83
+ return nil unless name.include?('auto')
84
+ @name = name[name.index('auto') + 1]
85
85
 
86
- # ~/.auto/automaton-plugin/lib/plugin.rb
86
+ # ~/.auto/auto-plugin/lib/plugin.rb
87
87
  @library = "#{directory}/lib/#{@name}.rb"
88
88
  @library = nil unless File.exists?(@library)
89
89
 
90
- # Automaton::Plugin
90
+ # Auto::Plugin
91
91
  if @library
92
92
  @module = File.basename(@library, '.rb').camelize
93
93
  else
94
94
  @module = nil
95
95
  end
96
96
 
97
- # ~/.auto/automaton-plugin/auto/task.rb
98
- @tasks = Dir["#{directory}/auto/**/*.rb"].sort.collect do |path|
99
- relative = path.gsub("#{directory}/auto/", '')
97
+ # ~/.auto/auto-plugin/auto/task.rb
98
+ @tasks = Dir["#{directory}/.auto/**/*.rb"].sort.collect do |path|
99
+ relative = path.gsub("#{directory}/.auto/", '')
100
100
  {
101
101
  :name => relative[0..-4].split('/').join(':').downcase,
102
102
  :path => path
@@ -1,4 +1,4 @@
1
- # By default, <tt>require 'automaton'</tt> uses Runner to re-evaluate the script.
1
+ # By default, <tt>require 'auto'</tt> uses Runner to re-evaluate the script.
2
2
  # If you don't want the environment (just the classes), require this file.
3
3
 
4
4
  require File.dirname(__FILE__) + "/alias"
@@ -1,4 +1,4 @@
1
- module Automaton
1
+ module Auto
2
2
  class Runner
3
3
 
4
4
  def initialize(path_or_task=nil, &block)
@@ -9,11 +9,10 @@ module Automaton
9
9
  def run(path_or_task=nil, &block)
10
10
  self.instance_eval(&block) if block
11
11
  if path_or_task
12
- task = Plugins.tasks(path_or_task)
13
- if task
14
- @path = task[:path]
15
- elsif File.exists?(path_or_task)
12
+ if File.exists?(path_or_task)
16
13
  @path = path_or_task
14
+ elsif task = Plugins.tasks(path_or_task)
15
+ @path = task[:path]
17
16
  end
18
17
  self.instance_eval(File.read(@path), @path) if @path
19
18
  end
File without changes
@@ -1,7 +1,7 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
2
 
3
- module Automaton
4
- describe Automaton::Plugins do
3
+ module Auto
4
+ describe Auto::Plugins do
5
5
 
6
6
  before(:all) do
7
7
  Plugins.add @fixtures = "#{SPEC}/plugins"
@@ -15,27 +15,27 @@ module Automaton
15
15
 
16
16
  it "should provide an array of plugin library files" do
17
17
  @libraries.should == [
18
- "#{@fixtures}/automaton-plugin2/lib/plugin2.rb",
19
- "#{@fixtures}/user-automaton-plugin-0.0.0/lib/plugin.rb"
18
+ "#{@fixtures}/auto-plugin-0.0.0/lib/plugin.rb",
19
+ "#{@fixtures}/auto-plugin2/lib/plugin2.rb"
20
20
  ]
21
21
  end
22
22
 
23
23
  it "should provide an array of module strings" do
24
- @modules.should == [ 'Plugin2', 'Plugin' ]
24
+ @modules.should == [ 'Plugin', 'Plugin2' ]
25
25
  end
26
26
 
27
27
  it "should provide a hash of plugin task information" do
28
28
  @tasks.should == [
29
29
  {
30
- :path => "#{@fixtures}/user-automaton-plugin-0.0.0/auto/plugin/task.rb",
30
+ :path => "#{@fixtures}/auto-plugin-0.0.0/.auto/plugin/task.rb",
31
31
  :name => "plugin:task"
32
32
  },
33
33
  {
34
- :path => "#{@fixtures}/automaton-plugin2/auto/plugin2/task.rb",
34
+ :path => "#{@fixtures}/auto-plugin2/.auto/plugin2/task.rb",
35
35
  :name => "plugin2:task"
36
36
  },
37
37
  {
38
- :path => "#{@fixtures}/automaton-plugin2/auto/plugin2/task2.rb",
38
+ :path => "#{@fixtures}/auto-plugin2/.auto/plugin2/task2.rb",
39
39
  :name => "plugin2:task2"
40
40
  }
41
41
  ]
@@ -1,7 +1,7 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
2
 
3
- module Automaton
4
- describe Automaton::Runner do
3
+ module Auto
4
+ describe Auto::Runner do
5
5
 
6
6
  before(:all) do
7
7
  Plugins.add @fixtures = "#{SPEC}/plugins"
@@ -9,8 +9,8 @@ module Automaton
9
9
  end
10
10
 
11
11
  it 'should require plugin library files' do
12
- $".include?("#{@fixtures}/user-automaton-plugin-0.0.0/lib/plugin.rb").should == true
13
- $".include?("#{@fixtures}/automaton-plugin2/lib/plugin2.rb").should == true
12
+ $".include?("#{@fixtures}/auto-plugin-0.0.0/lib/plugin.rb").should == true
13
+ $".include?("#{@fixtures}/auto-plugin2/lib/plugin2.rb").should == true
14
14
  end
15
15
 
16
16
  it 'should include all plugin library modules' do
@@ -1,4 +1,4 @@
1
- module Automaton
1
+ module Auto
2
2
  module Plugin
3
3
  def plugin
4
4
  true
@@ -1,4 +1,4 @@
1
- module Automaton
1
+ module Auto
2
2
  module Plugin2
3
3
  def plugin2
4
4
  true
@@ -1,15 +1,16 @@
1
- $TESTING=true
1
+ $testing = true
2
2
  SPEC = File.dirname(__FILE__)
3
3
  $:.unshift File.expand_path("#{SPEC}/../lib")
4
4
 
5
- require 'automaton/require'
5
+ require 'auto/require'
6
6
  require 'pp'
7
7
 
8
8
  Spec::Runner.configure do |config|
9
9
  end
10
10
 
11
+ # For use with rspec textmate bundle
11
12
  def debug(object)
12
13
  puts "<pre>"
13
14
  puts object.pretty_inspect.gsub('<', '&lt;').gsub('>', '&gt;')
14
15
  puts "</pre>"
15
- end
16
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: auto
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Winton Welsh
@@ -9,10 +9,19 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-06 00:00:00 -08:00
12
+ date: 2009-11-15 00:00:00 -08:00
13
13
  default_executable:
14
- dependencies: []
15
-
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: auto-terminal
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - "="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.1
24
+ version:
16
25
  description:
17
26
  email: mail@wintoni.us
18
27
  executables: []
@@ -22,28 +31,25 @@ extensions: []
22
31
  extra_rdoc_files:
23
32
  - README.markdown
24
33
  files:
25
- - config/externals.yml
26
- - lib/automaton/alias.rb
27
- - lib/automaton/class.rb
28
- - lib/automaton/plugins.rb
29
- - lib/automaton/require.rb
30
- - lib/automaton/runner.rb
31
- - lib/automaton/string.rb
32
- - lib/automaton.rb
34
+ - gemspec.rb
35
+ - lib/auto/alias.rb
36
+ - lib/auto/class.rb
37
+ - lib/auto/plugins.rb
38
+ - lib/auto/require.rb
39
+ - lib/auto/runner.rb
40
+ - lib/auto/string.rb
41
+ - lib/auto.rb
33
42
  - MIT-LICENSE
34
43
  - Rakefile
35
44
  - README.markdown
36
- - spec/automaton/plugins_spec.rb
37
- - spec/automaton/runner_spec.rb
38
- - spec/plugins/automaton-plugin2/auto/plugin2/task.rb
39
- - spec/plugins/automaton-plugin2/auto/plugin2/task2.rb
40
- - spec/plugins/automaton-plugin2/lib/plugin2.rb
41
- - spec/plugins/user-automaton-plugin-0.0.0/auto/plugin/task.rb
42
- - spec/plugins/user-automaton-plugin-0.0.0/lib/plugin.rb
45
+ - spec/auto/plugins_spec.rb
46
+ - spec/auto/runner_spec.rb
47
+ - spec/plugins/auto-plugin-0.0.0/lib/plugin.rb
48
+ - spec/plugins/auto-plugin2/lib/plugin2.rb
43
49
  - spec/spec.opts
44
50
  - spec/spec_helper.rb
45
51
  has_rdoc: true
46
- homepage: http://github.com/winton/automaton
52
+ homepage: http://github.com/winton/auto
47
53
  licenses: []
48
54
 
49
55
  post_install_message:
@@ -1,6 +0,0 @@
1
- automaton-questions:
2
- repo: git@github.com:winton/automaton-questions.git
3
- path: vendor/plugins
4
- automaton-terminal:
5
- repo: git@github.com:winton/automaton-terminal.git
6
- path: vendor/plugins
@@ -1,8 +0,0 @@
1
- require File.dirname(__FILE__) + "/automaton/require"
2
-
3
- module Automaton
4
- Runner.new do
5
- terminal($0)
6
- end
7
- exit
8
- end