srbc 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: dbd310003777e939ce2100c0b7ea9fe6d83e421a
4
+ data.tar.gz: 4fe63b776630b705bb6738ea54575c61feb21fb7
5
+ SHA512:
6
+ metadata.gz: e2fd9e9ed9f47ab3a544bfa6164375036ee5f3a00cd4d88b009f2701df272420dd0676dd72e74885d6bc00a078d591b993a8fff329421479e29ad65e2e5a50f2
7
+ data.tar.gz: 1557c13d3cf742defc035e05fd21d697ddb0ebe21aa4a810e2e9a138239c0861fb23acc78edd2134d421233a6c0ddf8df15f8d701e0c168a5119cd5ca69db52a
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .idea/
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in srbc.gemspec
4
+ gemspec
5
+ gem 'rspec'
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 ibondarenko
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,64 @@
1
+ # Srbc
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'srbc'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install srbc
18
+
19
+ ## Usage
20
+
21
+ Usage: You can run *.rb files, or
22
+ other in ruby, just print "main"
23
+ to execute "ruby main.rb".
24
+
25
+ If in folder same files contains
26
+ "main" (for example foo_main.rb,
27
+ bar_main.rb and main.rb) SRBC ask
28
+ you what file run.
29
+
30
+ When SRBC run default MS symbol
31
+ in console > replace with ~
32
+
33
+ You can use other executor.
34
+ Run "srbc -add:cucumber"
35
+ to add new executor.
36
+ Then run "srbc -cucumber" to start
37
+ Smart Ruby Console with cucumber executor.
38
+
39
+
40
+ Arguments:
41
+ -add:<exexutor> add executor
42
+ -<executor> run with executor
43
+ -help for this help
44
+ -list list of executors
45
+ no arguments run ruby executor
46
+
47
+
48
+ Comands:
49
+
50
+ | @help | this help |
51
+ | @list | extension list |
52
+ | @exit | exit from app |
53
+ | @add "*.rb" | add extension |
54
+
55
+ You can shortcut commands.
56
+ Example: @h for help
57
+
58
+ ## Contributing
59
+
60
+ 1. Fork it ( https://github.com/[my-github-username]/srbc/fork )
61
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
62
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
63
+ 4. Push to the branch (`git push origin my-new-feature`)
64
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/srbc ADDED
@@ -0,0 +1,56 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+ require 'readline'
4
+ require 'yaml'
5
+ require 'fileutils'
6
+ require_relative '../lib/srbc'
7
+
8
+ #if x=true gem run, when x=false gem will exit
9
+
10
+ # check how many options user specify
11
+ if ARGV.length >1
12
+ puts 'You can run ony one executor'
13
+
14
+ #todo: ?remove into gem. run without arguments
15
+ #if user add
16
+ elsif ARGV[0] =~/add:/
17
+ new_executor = ARGV[0].gsub( ' ','').gsub '-add:', ''
18
+ puts "Crate #{new_executor}"
19
+ srbc = SRBC.new(new_executor)
20
+ puts "Please, enter extension (in format *.rb')"
21
+ ext = $stdin.gets.chomp
22
+ srbc.read_settings
23
+ srbc.set_settings new_executor, ext
24
+ srbc.run
25
+
26
+ elsif ARGV[0] =~/help/
27
+ srbc = SRBC.new('ruby')
28
+ srbc.srbc_command('help')
29
+
30
+ elsif ARGV[0] =~/list/
31
+ srbc = SRBC.new('ruby')
32
+ srbc.read_settings
33
+ srbc.read_settings.each do |executor, extension|
34
+ puts "\n====="
35
+ puts "#{executor}"
36
+ puts '-----'
37
+ extension.each { |ext| puts " #{ext}"}
38
+ end
39
+
40
+ else
41
+
42
+ ARGV.empty? ? executor = 'ruby' : executor = ARGV[0].gsub('-','')
43
+ srbc = SRBC.new(executor)
44
+ puts "\nSmart Ruby Console #{SrbcVersion::VERSION}. Executor: #{executor}"
45
+ puts '__________________________'
46
+ srbc.read_settings
47
+ if srbc.lunched
48
+ puts "\n type @help for help\n\n"
49
+ end
50
+
51
+ #it's trap for blick ctrl+c
52
+ trap('INT') {puts "\nprint @exit"}
53
+
54
+ srbc.run
55
+
56
+ end
data/changelog.md ADDED
@@ -0,0 +1,17 @@
1
+ #0.0.2
2
+ command @list or @l print all executors
3
+ #0.0.3
4
+ add command @# to change executor
5
+ #0.0.4
6
+ fix empty ine bug
7
+ fix cd to root directory
8
+ #0.0.5
9
+ fix bug when with add first extension to new executor
10
+ #0.0.6
11
+ add command delete executor
12
+ #0.0.7
13
+ fix bug, when you try change psth to unknow disk
14
+ #0.0.8
15
+ remove downcasse
16
+ #0.0.9
17
+ minor changes
data/help ADDED
@@ -0,0 +1,51 @@
1
+ =======================
2
+
3
+ Usage: You can run *.rb files, or
4
+ other in ruby, just type "main"
5
+ to execute "ruby main.rb".
6
+
7
+ If in folder same files contains
8
+ "main" (for example foo_main.rb,
9
+ bar_main.rb and main.rb) SRBC ask
10
+ you what file run.
11
+
12
+ When SRBC run default MS symbol
13
+ in console > replace with~.
14
+ Every line will start with R :
15
+ R - is first letter of executor
16
+
17
+ You can use other executor.
18
+ Run "srbc -add:cucumber"
19
+ to add new executor.
20
+ Then run "srbc -cucumber" to start
21
+ Smart Ruby Console with cucumber executor.
22
+
23
+
24
+ Arguments:
25
+ -add:<exexutor> add executor
26
+ -<executor> run with executor
27
+ -help for this help
28
+ -list list of executors
29
+ no arguments run ruby executor
30
+
31
+
32
+ Comands:
33
+
34
+ shortcut command description
35
+ _________________________________________________
36
+ | @h | @help | this help |
37
+ | @l | @list | extension list |
38
+ | @e | @exit | exit from app |
39
+ | -- | @add "*.rb" | add extension |
40
+ | @c | @current | current executor |
41
+ | -- | @#<executor> | hot change executor |
42
+ | | | if executor not exits |
43
+ | | | will created new |
44
+ | -- | @delete <exc>| delete executor |
45
+ | -- | !<command> | run program. use when |
46
+ | | | have same name programm |
47
+ | | | and file, like pnig.rb |
48
+ __________________________________________________
49
+
50
+
51
+
data/lib/srbc.rb ADDED
@@ -0,0 +1,68 @@
1
+ require 'srbc/srbc_command'
2
+ require 'srbc/srbc_cli'
3
+
4
+
5
+ class SRBC
6
+ attr_accessor :settings, :lunched
7
+ include SrbcCommand
8
+ include SRBC_cli
9
+
10
+
11
+ def initialize(executor)
12
+ @ext = []
13
+ @gem_root = Gem.loaded_specs['srbc'].full_gem_path
14
+ @executor = executor
15
+ @settings ={}
16
+ @lunched = true
17
+ end
18
+
19
+ #write extension to file/ return - extension array
20
+ def set_settings(executor, extension)
21
+ if extension =~ /^\*\..*$/ && extension !~ /^\*\.$/
22
+ @ext ||= []
23
+ #сheck added extension early or not
24
+ unless @ext.include? extension
25
+ @ext << extension
26
+ else
27
+ puts 'Extension already added'
28
+ end
29
+ @settings[executor] = @ext
30
+ save_settings
31
+ else
32
+ puts 'Wrong format! You muts type "@add *.extenssion"'
33
+ end
34
+ end
35
+
36
+ def save_settings
37
+ File.open("#{@gem_root}/settings.yml", 'w') do |file|
38
+ file.write @settings.to_yaml
39
+ end
40
+ end
41
+
42
+
43
+ #try read settings, if not exsist crate settings file
44
+ def read_settings
45
+ @settings = YAML::load_file "#{@gem_root}/settings.yml"
46
+ end
47
+
48
+ def get_file_list (name)
49
+ file_name = name.split(" ")[0]
50
+ args = name.split(" ")[1..name.split(" ").length-1].join" "
51
+ file_list ={}
52
+
53
+ #get file list each extension specified in settings.yml
54
+ @ext.each do |extension|
55
+ file = Dir.glob extension
56
+
57
+ #delete files not compare with typed file name
58
+ file.delete_if {|f| f !~ /^#{file_name}/}
59
+ file.each do |file_nme|
60
+ file_list = file_list.merge Hash[file_nme, args]
61
+ end
62
+ end
63
+
64
+ file_list
65
+ end
66
+
67
+ end
68
+
@@ -0,0 +1,117 @@
1
+ #-*- coding:utf-8 -*-
2
+
3
+ module SRBC_cli
4
+ # contain commandline inetfeice
5
+ # and detect SRBC command execute, file or system programm
6
+
7
+ def run()
8
+
9
+ if @settings[@executor].nil?
10
+ puts "\n Executor not defined. Run srbc with -add:<executor> options "
11
+ self.runed = false
12
+ else
13
+ @ext = @settings[@executor]
14
+ end
15
+
16
+ while self.lunched do
17
+ #get current path
18
+ path = Dir.pwd
19
+ #wait command and realise history of command
20
+ command = Readline.readline("#{@executor.chr.upcase}# #{path.gsub "/", "\\"}~ ", true)
21
+ command = nil if command.nil?
22
+ if command =~ /^\s*$/ or Readline::HISTORY.to_a[-2] == command
23
+ Readline::HISTORY.pop
24
+ end
25
+
26
+ cmd = command.gsub("#{path}~ ", '')
27
+
28
+
29
+ #if user type command start with @ - run srbc command
30
+ if cmd =~ /^@/
31
+ self.srbc_command cmd.gsub "@", ""
32
+ elsif cmd == ''
33
+ cmd = ' '
34
+ else
35
+
36
+ case cmd.downcase
37
+
38
+ # command cd - SRBC change current work dir
39
+ when /cd/
40
+
41
+ if cmd =~ /\.\./ || cmd =~/^cd$/
42
+ temp_path = Dir.pwd.split '/'
43
+ if temp_path.length > 1
44
+ temp_path.delete_at temp_path.length-1
45
+ if temp_path.length > 1
46
+ path = temp_path.join "\\"
47
+ Dir.chdir path
48
+ else
49
+ Dir.chdir "#{temp_path[0]}\\"
50
+ end
51
+ end
52
+ else
53
+ begin
54
+ Dir.chdir cmd.gsub 'cd ', ''
55
+ rescue
56
+ puts 'Wrong path'
57
+ end
58
+ end
59
+
60
+ # command X: change current work dir if user whant change volume
61
+ when /^\w:$/
62
+ begin
63
+ Dir.chdir cmd
64
+ rescue
65
+ puts "Path not found"
66
+ end
67
+
68
+ #run with skip executor.
69
+ # Use when you whant execute system command ping and have ping.rb un current folder
70
+ when /^\!/
71
+ run_program cmd.gsub '!',''
72
+
73
+ # run app or other program
74
+ when /^$|^ *$/
75
+ #skip when empty command
76
+ else
77
+
78
+ file_list = self.get_file_list cmd
79
+
80
+ #run file if find only one
81
+ if file_list.length == 1
82
+ file_list.each do |name, args|
83
+ run_file name, args
84
+ end
85
+
86
+ # не найдено фалов - значит команда
87
+ elsif file_list.length == 0
88
+ p "run command #{cmd}"
89
+ run_program cmd
90
+
91
+ # в остальных случаях файлов > 1
92
+ else
93
+
94
+ puts 'We find, more than one file:'
95
+
96
+ i = 0
97
+ numbered_files = {}
98
+ puts " 0 | Cancel "
99
+ file_list.each do |file|
100
+ i += 1
101
+ puts " #{i} | #{file[0]}"
102
+ numbered_files[i] = file[0]
103
+ end
104
+ num_file = -1
105
+ while num_file < 0
106
+ puts "Choose file to run (type @ and number of file)"
107
+ num_file = gets.chomp.gsub("@", "").to_i
108
+ if num_file > 0
109
+ run_file numbered_files[num_file], file_list[numbered_files[num_file]]
110
+ end
111
+ end
112
+ end
113
+ end
114
+ end
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,76 @@
1
+ require_relative 'version'
2
+ module SrbcCommand
3
+
4
+
5
+ #method to execute command sterst with @
6
+ def srbc_command(command)
7
+
8
+ case command.downcase
9
+ when 'e','exit'
10
+ self.lunched = false
11
+ puts 'Exiting Smart Ruby Console'
12
+
13
+ when 'h','help'
14
+ puts "Smart Ruby Console help SRBC #{SrbcVersion::VERSION}"
15
+ File.open("#{@gem_root}/help", 'r') do |helpfile|
16
+ while line=helpfile.gets
17
+ puts line
18
+ end
19
+ end
20
+
21
+ #hot change executor
22
+ when /^#/
23
+ @executor = command.gsub(' ','').gsub '#', ''
24
+ @ext = @settings[@executor]
25
+ if @ext.nil?
26
+ puts "You use #{@executor} first time. Please add extension!"
27
+ ext = gets.chomp
28
+ set_settings @executor, ext
29
+ end
30
+
31
+ when 'l','list'
32
+ puts "Current [#{@executor}]:"
33
+ puts @ext
34
+ @settings.each do |executor, extensions|
35
+ unless executor == @executor
36
+ puts "\n"
37
+ puts "[#{executor}]"
38
+ puts extensions
39
+ end
40
+ end
41
+
42
+ when /^add/
43
+ new_ext = command.gsub 'add ', ''
44
+
45
+ set_settings @executor, new_ext
46
+ when 'c','current'
47
+ puts "\nCurrent executor: #{@executor}"
48
+
49
+ when /^delete/
50
+ executor_to_delete = command.gsub 'delete ', ''
51
+ if @settings[executor_to_delete].nil?
52
+ puts "Can't find #{executor_to_delete}"
53
+ else
54
+ if @executor == executor_to_delete
55
+ @executor = 'ruby'
56
+ end
57
+ @settings.delete (executor_to_delete)
58
+ save_settings
59
+ puts "#{executor_to_delete} deleted"
60
+ end
61
+
62
+ else
63
+ puts "Unknow SRBC command. Use @help for help"
64
+ end
65
+
66
+ end
67
+
68
+ def run_program(name)
69
+ system "#{name}"
70
+ end
71
+
72
+ def run_file(name, args="")
73
+ #puts "RUNN: ruby #{name} #{args}"
74
+ system "#{@executor} #{name} #{args}"
75
+ end
76
+ end
@@ -0,0 +1,3 @@
1
+ module SrbcVersion
2
+ VERSION = "0.0.9"
3
+ end
data/settings.yml ADDED
@@ -0,0 +1,3 @@
1
+ ---
2
+ ruby:
3
+ - '*.rb'
data/srbc.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'srbc/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "srbc"
8
+ spec.version = SrbcVersion::VERSION
9
+ spec.authors = ["Ilya Bondarenko"]
10
+ spec.email = ["bondarenko.ik@gmail.com"]
11
+ spec.summary = %q{SRBC extend windows comand line. Provide easy way to run ruby scripts}
12
+ spec.description = %q{Start ruby Console with extend features. Let execute ruby files without type "ruby" and "rb" extention.For exmple: type "main" to execute "runy main.rb". Also you can add custom executor: cucumber, python, ping or what you want.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+ spec.executables << 'srbc'
24
+ end
@@ -0,0 +1,16 @@
1
+ require 'rspec'
2
+ require_relative '../lib/srbc/srbc_command'
3
+
4
+ describe SrbcCommand do
5
+ include SrbcCommand
6
+
7
+ it 'srbc should exit when command e or exit' do
8
+ command ="e"
9
+ srbc_command(command)
10
+ $x.should eq false
11
+ $x = true
12
+ command = 'exit'
13
+ srbc_command command
14
+ $x.should eq false
15
+ end
16
+ end
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: srbc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.9
5
+ platform: ruby
6
+ authors:
7
+ - Ilya Bondarenko
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: 'Start ruby Console with extend features. Let execute ruby files without
42
+ type "ruby" and "rb" extention.For exmple: type "main" to execute "runy main.rb".
43
+ Also you can add custom executor: cucumber, python, ping or what you want.'
44
+ email:
45
+ - bondarenko.ik@gmail.com
46
+ executables:
47
+ - srbc
48
+ extensions: []
49
+ extra_rdoc_files: []
50
+ files:
51
+ - .gitignore
52
+ - Gemfile
53
+ - LICENSE.txt
54
+ - README.md
55
+ - Rakefile
56
+ - bin/srbc
57
+ - changelog.md
58
+ - help
59
+ - lib/srbc.rb
60
+ - lib/srbc/srbc_cli.rb
61
+ - lib/srbc/srbc_command.rb
62
+ - lib/srbc/version.rb
63
+ - settings.yml
64
+ - srbc.gemspec
65
+ - test/srbc_command_spec.rb
66
+ homepage: ''
67
+ licenses:
68
+ - MIT
69
+ metadata: {}
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements: []
85
+ rubyforge_project:
86
+ rubygems_version: 2.0.14
87
+ signing_key:
88
+ specification_version: 4
89
+ summary: SRBC extend windows comand line. Provide easy way to run ruby scripts
90
+ test_files:
91
+ - test/srbc_command_spec.rb
92
+ has_rdoc: