Bashy 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,8 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+
6
+ coverage
7
+ rdoc
8
+ .yardoc
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ $:.push File.expand_path("../lib", __FILE__)
4
+ require "Bashy/version"
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "Bashy"
8
+ s.version = Bashy::VERSION
9
+ s.authors = ["da99"]
10
+ s.email = ["i-hate-spam-45671204@mailinator.com"]
11
+ s.homepage = "https://github.com/da99/Bashy"
12
+ s.summary = %q{Classes to generate common Bash scripting tasks.}
13
+ s.description = %q{
14
+ Generate Bash code for common tasks (creating files/dirs, chmod-ing, chown-ing, etc).
15
+ }
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_development_dependency 'bacon'
23
+ s.add_development_dependency 'rake'
24
+ s.add_development_dependency 'Bacon_Colored'
25
+ s.add_development_dependency 'pry'
26
+
27
+ # Specify any dependencies here; for example:
28
+ s.add_runtime_dependency 'Get_Set'
29
+ end
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ source "http://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in Bob.gemspec
6
+ gemspec
@@ -0,0 +1,50 @@
1
+
2
+ Bashy
3
+ ================
4
+
5
+ Classes to help you generate common tasks using bash:
6
+
7
+ * creating/deleting files and directories.
8
+ * chmod
9
+ * chdir
10
+
11
+ Installation
12
+ ------------
13
+
14
+ gem install Bashy
15
+
16
+ Usage
17
+ ------
18
+
19
+ require "Bashy"
20
+
21
+ cmd = Bashy_File.new { |o|
22
+
23
+ o.mode 0770
24
+ o.sudo true
25
+ o.path "/my_secret_dir"
26
+
27
+ }.create
28
+
29
+ `#{cmd}`
30
+
31
+ Available classes:
32
+
33
+ * Bashy\_File
34
+ * Bashy\_Dir
35
+ * Bashy\_Apt
36
+
37
+ Run Tests
38
+ ---------
39
+
40
+ git clone git@github.com:da99/Bashy.git
41
+ cd Bashy
42
+ bundle update
43
+ bundle exec bacon spec/main.rb
44
+
45
+ "I hate writing."
46
+ -----------------------------
47
+
48
+ If you know of existing software that makes the above redundant,
49
+ please tell me. The last thing I want to do is maintain code.
50
+
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/gem_tasks"
@@ -0,0 +1,49 @@
1
+ require 'Bashy/version'
2
+ require 'Get_Set'
3
+
4
+ class Bashy
5
+
6
+ module Base
7
+
8
+ include Get_Set::DSL
9
+ attr_get_set :name
10
+
11
+ def run cmd
12
+ cmd
13
+ end
14
+
15
+ def initialize
16
+ yield self
17
+ end
18
+
19
+ def sudo val = :_RETURN_
20
+ if val == :_RETURN_
21
+ @sudo ? 'sudo' : nil
22
+ else
23
+ @sudo = val
24
+ end
25
+ end
26
+
27
+ def user_and_group val = :_RETURN_
28
+ if val == :_RETURN_
29
+ og = [@user_and_group, @user_and_group]
30
+ .compact
31
+ .map(&:to_s)
32
+ .map(&:strip)
33
+ .reject(&:empty?)
34
+ .join(':')
35
+
36
+ return nil if og.empty?
37
+ og
38
+ else
39
+ @user_and_group = val
40
+ end
41
+ end
42
+
43
+ end # === Base
44
+
45
+ end # === class Bashy
46
+
47
+ require 'Bashy/Bashy_Apt'
48
+ require 'Bashy/Bashy_File'
49
+ require 'Bashy/Bashy_Dir'
@@ -0,0 +1,24 @@
1
+
2
+
3
+ class Bashy_Apt
4
+
5
+ module Base
6
+
7
+ include Get_Set::DSL
8
+ attr_get_set :depends
9
+
10
+ def install
11
+ run %@ #{sudo} apt-get -y install #{((depends || []) + [name]).join(' ')} @
12
+ end
13
+
14
+ def remove
15
+ run %@ #{sudo} apt-get -y purge #{name} @
16
+ end
17
+
18
+ end # === Base
19
+
20
+ include Bashy::Base
21
+ include Base
22
+
23
+ end # === Bashy_Apt
24
+
@@ -0,0 +1,23 @@
1
+
2
+
3
+ class Bashy_Dir
4
+
5
+ module Base
6
+
7
+ include Get_Set::DSL
8
+ attr_get_set :path
9
+
10
+ def create
11
+ run %@ #{sudo} mkdir -p #{path} @
12
+ end
13
+
14
+ def delete
15
+ run %@ #{sudo} rm -r #{path} @
16
+ end
17
+
18
+ end # === Base
19
+
20
+ include Bashy::Base
21
+ include Base
22
+
23
+ end # === Bashy_Dir
@@ -0,0 +1,44 @@
1
+
2
+ class Bashy_File
3
+
4
+ module Base
5
+
6
+ include Get_Set::DSL
7
+ attr_get_set :path, :content, :mode
8
+
9
+ def create
10
+ run cmd(%@ echo #{content.inspect} > #{sudo} tee #{path} @)
11
+ end
12
+
13
+ def append
14
+ run cmd(%@ echo #{content.inspect} >> #{sudo} tee #{path}@)
15
+ end
16
+
17
+ def cmd_chmod_file
18
+ sudo = self.sudo || ''
19
+ mod = self.mode.to_s.strip
20
+
21
+ return nil if mod.empty?
22
+ "#{sudo} chmod #{mod} #{path}"
23
+ end
24
+
25
+ def cmd_chown_file
26
+ og = user_and_group
27
+ return nil unless og
28
+ "#{sudo} chown #{og} #{path}"
29
+ end # === cmd_chown_file
30
+
31
+ def cmd cmd
32
+ [
33
+ cmd,
34
+ cmd_chmod_file,
35
+ cmd_chown_file
36
+ ].compact.join(" && ")
37
+ end
38
+
39
+ end # === Base
40
+
41
+ include Bashy::Base
42
+ include Base
43
+
44
+ end # === Bashy_File
@@ -0,0 +1,3 @@
1
+ class Bashy
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,15 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.print e.message, "\n"
7
+ $stderr.print "Run `bundle install` to install missing gems\n"
8
+ exit e.status_code
9
+ end
10
+ require 'bacon'
11
+
12
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+
15
+ Bacon.summary_on_exit
@@ -0,0 +1,15 @@
1
+
2
+ require File.expand_path('spec/helper')
3
+ require 'Bashy'
4
+ require 'Bacon_Colored'
5
+ require 'pry'
6
+
7
+
8
+ # ======== Include the tests.
9
+ if ARGV.size > 1 && ARGV[1, ARGV.size - 1].detect { |a| File.exists?(a) }
10
+ # Do nothing. Bacon grabs the file.
11
+ else
12
+ Dir.glob('spec/tests/*.rb').each { |file|
13
+ require File.expand_path(file.sub('.rb', '')) if File.file?(file)
14
+ }
15
+ end
@@ -0,0 +1,100 @@
1
+
2
+ describe "Bashy_Apt" do
3
+
4
+ it "provides sudo as an option" do
5
+ Bashy_Apt.new { |o|
6
+ o.sudo true
7
+ o.name "open-ssh"
8
+ }.install.strip
9
+ .should == "sudo apt-get -y install open-ssh"
10
+ end
11
+
12
+ it "provides install as a command" do
13
+ Bashy_Apt.new { |o|
14
+ o.name "open-ssh"
15
+ }.install.strip
16
+ .should == "apt-get -y install open-ssh"
17
+ end
18
+
19
+ it "provides remove as a command" do
20
+ Bashy_Apt.new { |o|
21
+ o.name "open-ssh"
22
+ }.remove.strip
23
+ .should == "apt-get -y purge open-ssh"
24
+ end
25
+
26
+ end # === Bashy_Apt
27
+
28
+ describe "Bashy_Dir" do
29
+
30
+ it "provides sudo as an option" do
31
+ Bashy_Dir.new { |o|
32
+ o.sudo true
33
+ o.path "/tmp/Delet"
34
+ }.create.strip
35
+ .should == "sudo mkdir -p /tmp/Delet"
36
+ end
37
+
38
+ it "provides create as a command" do
39
+ Bashy_Dir.new { |o|
40
+ o.path "/tmp/new.txt"
41
+ }.create.strip
42
+ .should == "mkdir -p /tmp/new.txt"
43
+ end
44
+
45
+ it "provides delete as a command" do
46
+ Bashy_Dir.new { |o|
47
+ o.path "/tmp/old.txt"
48
+ }.delete.strip
49
+ .should == "rm -r /tmp/old.txt"
50
+ end
51
+
52
+ end # === Bashy_Dir
53
+
54
+ describe "Bashy_File" do
55
+
56
+ it "provides sudo as an option" do
57
+ Bashy_File.new { |f|
58
+ f.sudo true
59
+ f.content "a"
60
+ f.path "/tmp/delete.txt"
61
+ }.create.strip
62
+ .should == "echo #{'a'.inspect} > sudo tee /tmp/delete.txt"
63
+ end
64
+
65
+ it "provides create as a command" do
66
+ Bashy_File.new { |f|
67
+ f.content "my content"
68
+ f.path "/tmp/delete.txt"
69
+ }.create.strip
70
+ .should == "echo #{'my content'.inspect} > tee /tmp/delete.txt"
71
+ end
72
+
73
+ it "provides append as a command" do
74
+ Bashy_File.new { |f|
75
+ f.content "my line"
76
+ f.path "/tmp/delete.txt"
77
+ }.append.strip
78
+ .should == "echo #{'my line'.inspect} >> tee /tmp/delete.txt"
79
+ end
80
+
81
+ it "provides chmod as an option" do
82
+ Bashy_File.new { |f|
83
+ f.content "my file"
84
+ f.path "/tmp/delete.txt"
85
+ f.mode "0644"
86
+ }.create.strip.split(%r! +&& +!).last
87
+ .should == %@chmod 0644 /tmp/delete.txt@
88
+ end
89
+
90
+ it "provides chown as an option" do
91
+ Bashy_File.new { |f|
92
+ f.content "new file"
93
+ f.path "/tmp/new.txt"
94
+ f.user_and_group "bob"
95
+ }.create.strip.split(%r! +&& +!).last
96
+ .should == %@chown bob:bob /tmp/new.txt@
97
+ end
98
+
99
+ end # === Bashy_File
100
+
@@ -0,0 +1,13 @@
1
+
2
+ bins = Dir.glob("bin/*")
3
+
4
+ unless bins.empty?
5
+ describe "permissions of bin/" do
6
+ bins.each { |file|
7
+ it "should chmod 755 for: #{file}" do
8
+ `stat -c %a #{file}`.strip
9
+ .should.be == "755"
10
+ end
11
+ }
12
+ end # === permissions of bin/
13
+ end # === unless bins.empty?
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: Bashy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - da99
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bacon
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: Bacon_Colored
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: pry
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: Get_Set
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ description: ! "\n Generate Bash code for common tasks (creating files/dirs, chmod-ing,
95
+ chown-ing, etc).\n "
96
+ email:
97
+ - i-hate-spam-45671204@mailinator.com
98
+ executables: []
99
+ extensions: []
100
+ extra_rdoc_files: []
101
+ files:
102
+ - .gitignore
103
+ - Bashy.gemspec
104
+ - Gemfile
105
+ - README.md
106
+ - Rakefile
107
+ - lib/Bashy.rb
108
+ - lib/Bashy/Bashy_Apt.rb
109
+ - lib/Bashy/Bashy_Dir.rb
110
+ - lib/Bashy/Bashy_File.rb
111
+ - lib/Bashy/version.rb
112
+ - spec/helper.rb
113
+ - spec/main.rb
114
+ - spec/tests/Bashy.rb
115
+ - spec/tests/bin.rb
116
+ homepage: https://github.com/da99/Bashy
117
+ licenses: []
118
+ post_install_message:
119
+ rdoc_options: []
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ none: false
124
+ requirements:
125
+ - - ! '>='
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubyforge_project:
136
+ rubygems_version: 1.8.19
137
+ signing_key:
138
+ specification_version: 3
139
+ summary: Classes to generate common Bash scripting tasks.
140
+ test_files: []