Skip to content

Commit

Permalink
Added Travis config file with CodeClimate. Refactored more code out i…
Browse files Browse the repository at this point in the history
…nto own methods.
  • Loading branch information
kaspernj committed May 28, 2014
1 parent 518533d commit 116d2ee
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 17 deletions.
18 changes: 18 additions & 0 deletions .travis.yml
@@ -0,0 +1,18 @@
language: ruby
rvm:
- ruby-1.9.3-p484

before_script:
- apt-get install php5-cli

notifications:
email: false

cache:
- bundler

addons:
code_climate:
repo_token: d388156debf9e8c47dc04bd00e0edeefb7d3b9b3c1506304359271d9efe1f714

script: "bundle exec rspec --format progress"
2 changes: 2 additions & 0 deletions Gemfile
Expand Up @@ -15,3 +15,5 @@ group :development do
gem "bundler", ">= 1.0.0"
gem "jeweler", "~> 1.8.3"
end

gem "codeclimate-test-reporter", group: :test, require: nil
2 changes: 1 addition & 1 deletion include/proxy_object.rb
Expand Up @@ -46,4 +46,4 @@ def __get_var(name)
def method_missing(method_name, *args)
return @args[:php].send(:type => :object_call, :method => method_name, :args => @args[:php].parse_data(args), :id => @args[:id])
end
end
end
38 changes: 22 additions & 16 deletions lib/php_process.rb
Expand Up @@ -46,6 +46,22 @@ def objects_unsetter(id)
# php = PhpProcess.new(:debug => true)
INITIALIZE_VALID_ARGS = [:debug, :debug_output, :debug_stderr, :cmd_php, :on_err]
def initialize(args = {})
parse_args_and_set_vars(args)
start_php_process
check_alive
$stderr.puts "PHP-script ready." if @debug
start_read_loop

if block_given?
begin
yield(self)
ensure
self.destroy
end
end
end

def parse_args_and_set_vars(args)
args.each do |key, val|
raise "Invalid argument: '#{key}'." unless INITIALIZE_VALID_ARGS.include?(key)
end
Expand All @@ -65,7 +81,9 @@ def initialize(args = {})
@callbacks = {}
@callbacks_count = 0
@callbacks_mutex = Mutex.new

end

def start_php_process
if RUBY_ENGINE == "jruby"
pid, @stdin, @stdout, @stderr = IO.popen4(php_cmd_as_string)
else
Expand All @@ -79,19 +97,7 @@ def initialize(args = {})
@stdout.set_encoding("utf-8:iso-8859-1")

@stderr_handler = ::PhpProcess::StderrHandler.new(:stderr => @stderr, :php_process => self)

start_out_reader_thread
check_alive
$stderr.print "PHP-script ready.\n" if @debug
start_read_loop

if block_given?
begin
yield(self)
ensure
self.destroy
end
end
end

#Returns various info in a hash about the object-cache on the PHP-side.
Expand Down Expand Up @@ -230,7 +236,7 @@ def parse_data(data)
def constant_val(name)
const_name = name.to_s

if !@constant_val_cache.key?(const_name)
unless @constant_val_cache.key?(const_name)
@constant_val_cache[const_name] = self.send(:type => :constant_val, :name => name)
end

Expand Down Expand Up @@ -461,7 +467,7 @@ def start_read_loop

def read_loop
@stdout.each_line do |line|
parsed = parse_line(line.to_s)
parsed = parse_line(line.to_s.strip)
next if parsed == :next
id, type, args = parsed[:id], parsed[:type], parsed[:args]
$stderr.print "Received: #{id}:#{type}:#{args}\n" if @debug
Expand All @@ -477,7 +483,7 @@ def read_loop
end

def parse_line(line)
if line.strip.empty? || @stdout.closed?
if line.empty? || @stdout.closed?
$stderr.puts "Got empty line from process - skipping: #{line}" if @debug
return :next
end
Expand Down
3 changes: 3 additions & 0 deletions spec/spec_helper.rb
@@ -1,3 +1,6 @@
require "codeclimate-test-reporter"
CodeClimate::TestReporter.start

$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'rspec'
Expand Down

0 comments on commit 116d2ee

Please sign in to comment.