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.
-
#repo ⇒ Object
Returns the value of attribute repo.
Instance Method Summary collapse
- #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'].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}" rescue LoadError puts <<-DOC.gsub(/^(\s*\|)/,'') |\e[33m#{self._name_}\e[0m | \e[31mSorry,doesn't support < #{scm} > now.\e[0m | \e[31mYou can define your Scm-Type in ~/.eo/scm.\e[0m DOC 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
65 66 67 68 69 |
# File 'lib/eo/repository.rb', line 65 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 |
#repo ⇒ Object
Returns the value of attribute repo.
4 5 6 |
# File 'lib/eo/repository.rb', line 4 def repo @repo end |
Instance Method Details
#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 <<-DOC.gsub(/^\s*\|/,'') |Usage : | update Update | shell/sh Goto shell | help/h Show this help message | q Quit this shell | Q Exit this program | <Hash Method> Run | <Your Method> Run.if undefined by above | <Shell Command> Run.if undefined by above |e.g:\n \e[32m pwd \e[0m => The repository's path DOC end |
#shell ⇒ Object Also known as: sh
60 61 62 |
# File 'lib/eo/repository.rb', line 60 def shell system("sh") end |