Class: DesignShellServer::Core
- Inherits:
-
Object
- Object
- DesignShellServer::Core
- Defined in:
- lib/designshellserver/core.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
Instance Method Summary collapse
- #cache_dir ⇒ Object
-
#initialize(aContext) ⇒ Core
constructor
A new instance of Core.
- #make_command(aLine) ⇒ Object
- #run ⇒ Object
- #working_dir_from_site(aSite) ⇒ Object
Constructor Details
#initialize(aContext) ⇒ Core
Returns a new instance of Core.
6 7 8 |
# File 'lib/designshellserver/core.rb', line 6 def initialize(aContext) @context = aContext end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
4 5 6 |
# File 'lib/designshellserver/core.rb', line 4 def context @context end |
Instance Method Details
#cache_dir ⇒ Object
30 31 32 |
# File 'lib/designshellserver/core.rb', line 30 def cache_dir @cache_dir ||= MiscUtils.append_slash(@context.credentials[:cache_dir] || MiscUtils.make_temp_dir('DesignShellServer')) end |
#make_command(aLine) ⇒ Object
10 11 12 13 14 |
# File 'lib/designshellserver/core.rb', line 10 def make_command(aLine) command_name = aLine.scan(/^[A-Z0-9_]+/).pop.to_nil return nil unless command_name && DesignShellServer::Command.instance_methods.include?(command_name) return DesignShellServer::Command.new(self,aLine,command_name) end |
#run ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/designshellserver/core.rb', line 16 def run if line = ENV['SSH_ORIGINAL_COMMAND'] command = make_command(line) command.execute else @context.stdout.print "\n>" @context.stdin.each_line do |line| line.chomp! "\n" command = make_command(line) command.execute @context.stdout.print "\n>" end end end |
#working_dir_from_site(aSite) ⇒ Object
34 35 36 37 38 |
# File 'lib/designshellserver/core.rb', line 34 def working_dir_from_site(aSite) return nil unless aSite aSite.gsub!(/[^a-zA-Z0-9.\-_]/,'_') File.join(cache_dir,aSite) end |