Class: Repository
- Inherits:
-
Object
- Object
- Repository
- Defined in:
- lib/eo/repository.rb
Instance Attribute Summary collapse
-
#_name_ ⇒ Object
Returns the value of attribute name.
-
#autorun ⇒ Object
Returns the value of attribute autorun.
-
#path ⇒ Object
Returns the value of attribute path.
-
#pushable ⇒ Object
Returns the value of attribute pushable.
-
#repo ⇒ Object
Returns the value of attribute repo.
-
#skip ⇒ Object
Returns the value of attribute skip.
Instance Method Summary collapse
- #delete ⇒ Object
- #help ⇒ Object (also: #h)
-
#initialize(opt = {}) ⇒ Repository
constructor
A new instance of Repository.
- #method_missing(m, *args) ⇒ Object
- #shell ⇒ Object (also: #sh)
Constructor Details
#initialize(opt = {}) ⇒ Repository
Returns a new instance of Repository.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/eo/repository.rb', line 6 def initialize(opt={}) ['repo','_name_','autorun','skip','pushable'].each do |x| eval "self.#{x} = opt.delete('#{x}')" end self.path = File.(opt['path']) if opt['path'] begin scm = opt['scm'] || 'git' require "scm/#{scm.downcase}" extend eval "Scm::#{scm.capitalize.gsub(/-(\w)/) { $1.to_s.upcase}}" rescue LoadError puts "|\\e[33m\#{self._name_}\\e[0m\n| \\e[31mSorry,doesn't support < \#{scm} > now.\\e[0m\n| \\e[31mYou can define your Scm-Type in ~/.eo/scm.\\e[0m\n".gsub(/^(\s*\|)/,'') exit 0 end if opt['cmd'] # Define Your Methods opt['cmd'].each do |key,value| # Hack, Can't use defined_method to replace a extend method eval("def self.#{key}; #{value} ; end") (@defined_methods ||= [] ) << [key,value] end end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args) ⇒ Object
75 76 77 78 79 |
# File 'lib/eo/repository.rb', line 75 def method_missing(m,*args) # method missing -> shell command result = system(m.to_s + " " + args.join(' ')) puts "\e[31mlol, Some Wrong?\e[0m" unless result end |
Instance Attribute Details
#_name_ ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/eo/repository.rb', line 4 def _name_ @_name_ end |
#autorun ⇒ Object
Returns the value of attribute autorun.
4 5 6 |
# File 'lib/eo/repository.rb', line 4 def autorun @autorun end |
#path ⇒ Object
Returns the value of attribute path.
4 5 6 |
# File 'lib/eo/repository.rb', line 4 def path @path end |
#pushable ⇒ Object
Returns the value of attribute pushable.
4 5 6 |
# File 'lib/eo/repository.rb', line 4 def pushable @pushable end |
#repo ⇒ Object
Returns the value of attribute repo.
4 5 6 |
# File 'lib/eo/repository.rb', line 4 def repo @repo end |
#skip ⇒ Object
Returns the value of attribute skip.
4 5 6 |
# File 'lib/eo/repository.rb', line 4 def skip @skip end |
Instance Method Details
#delete ⇒ Object
65 66 67 68 69 70 71 72 73 |
# File 'lib/eo/repository.rb', line 65 def delete if readline("\e[33mAre Your Sure ? \e[0m") !~ /q|n/i if self.path && !self.path.empty? FileUtils.rm_rf(self.path) else puts "\e[31mDon't know how to delete the repository!\e[0m" end end end |
#help ⇒ Object Also known as: h
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/eo/repository.rb', line 36 def help if @defined_methods puts "Your Defined Methods :" @defined_methods.each do |x| puts " %-18s %s" % [x.first, x.last] end puts "\n" end puts "|Usage :\n| update Update\n| shell/sh Goto shell\n| help/h Show this help message\n| q Quit this shell\n| Q Exit this program\n| <Hash Method> Run\n| <Your Method> Run.if undefined by above\n| <Shell Command> Run.if undefined by above\n|e.g:\\n \\e[32m pwd \\e[0m => The repository's path\n".gsub(/^\s*\|/,'') end |
#shell ⇒ Object Also known as: sh
60 61 62 |
# File 'lib/eo/repository.rb', line 60 def shell system(Eo::Config['shell']) end |