Skip to content

Commit

Permalink
more rubocop cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
skierkowski committed Jul 29, 2014
1 parent 58c5633 commit 86ae972
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 55 deletions.
7 changes: 4 additions & 3 deletions Rakefile
@@ -1,11 +1,12 @@
# encoding: UTF-8

require 'bundler/gem_tasks'
require 'rspec/core/rake_task'

# RSpec::Core::RakeTask.new(:spec)
desc "Run specs"
desc 'Run specs'
RSpec::Core::RakeTask.new do |t|
t.verbose = false
t.rspec_opts = '--color --order random'
end

task :default => :spec
task default: :spec
31 changes: 17 additions & 14 deletions factor.gemspec
@@ -1,20 +1,23 @@
$:.push File.expand_path("../lib", __FILE__)
require 'factor/version'
# encoding: UTF-8
$LOAD_PATH.push File.expand_path('../lib', __FILE__)
require 'factor/version'

Gem::Specification.new do |s|
s.name = "factor"
Gem::Specification.new do |s|
s.name = 'factor'
s.version = Factor::VERSION
s.platform = Gem::Platform::RUBY
s.authors = ["Maciej Skierkowski"]
s.email = ["maciej@factor.io"]
s.homepage = "https://factor.io"
s.summary = %q{CLI to manager workflows on Factor.io}
s.description = %q{CLI to manager workflows on Factor.io}
s.authors = ['Maciej Skierkowski']
s.email = ['maciej@factor.io']
s.homepage = 'https://factor.io'
s.summary = 'CLI to manager workflows on Factor.io'
s.description = 'CLI to manager workflows on Factor.io'

s.files = %x{git ls-files}.split("\n")
s.test_files = %x{git ls-files -- {test,spec,features}/*}.split("\n")
s.executables = %x{git ls-files -- bin/*}.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]
s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map do |f|
File.basename(f)
end
s.require_paths = ['lib']

s.add_runtime_dependency 'commander', '~> 4.2.0'
s.add_runtime_dependency 'rest_client', '~> 1.7.3'
Expand All @@ -24,4 +27,4 @@
s.add_development_dependency 'codeclimate-test-reporter', '~> 0.3.0'
s.add_development_dependency 'rspec', '~> 3.0.0'
s.add_development_dependency 'rake', '~> 10.3.2'
end
end
25 changes: 11 additions & 14 deletions lib/commands/base.rb
Expand Up @@ -7,7 +7,6 @@

module Factor
module Commands

# Base command with common methods used by all commands
class Command
DEFAULT_FILENAME = {
Expand Down Expand Up @@ -51,11 +50,11 @@ def load_config(options = {})
def load_config_data(config_type, options = {})
relative_path = options[config_type] || DEFAULT_FILENAME[config_type]
absolute_path = File.expand_path(relative_path)
info message: "Loading #{config_type.to_s} from #{absolute_path}"
info message: "Loading #{config_type} from #{absolute_path}"
data = YAML.load(File.read(absolute_path))
configatron[config_type].configure_from_hash(data)
rescue => ex
exception "Couldn't load #{config_type.to_s} from #{absolute_path}", ex
exception "Couldn't load #{config_type} from #{absolute_path}", ex
end

def log_line(section, options = {})
Expand All @@ -78,19 +77,17 @@ def format_section(section)
end

def tag(options)
tag = ''
if options['workflow_id'] && options['instance_id']
tag = "[#{options['workflow_id']}:#{options['instance_id']}]"
elsif options['workflow_id'] && !options['instance_id']
tag = "[#{options['workflow_id']}]"
elsif !options['workflow_id'] && options['instance_id']
tag = "[#{options['instance_id']}]"
end
tag
primary = options['service_id'] || options['instance_id']
secondary = if options['service_id'] && options['instance_id']
":#{options['instane_id']}"
else
''
end
primary ? "[#{primary}#{secondary}]" : ''
end

def time
Time.now.localtime.strftime('%m/%d/%y %T.%L')
Time.now.localtime.strftime('%m/%d/%y %T.%L')
end

def write(message)
Expand All @@ -100,4 +97,4 @@ def write(message)
end
end
end
end
end
10 changes: 4 additions & 6 deletions lib/commands/workflows.rb
Expand Up @@ -7,15 +7,13 @@

module Factor
module Commands

# Workflow is a Command to start the factor runtime from the CLI
class Workflow < Factor::Commands::Command

def initialize
@workflows = {}
end

def server(args, options)
def server(_args, options)
config_settings = {}
config_settings[:credentials] = options.credentials
config_settings[:connectors] = options.connectors
Expand Down Expand Up @@ -46,7 +44,7 @@ def load_all_workflows(workflow_filename)
def block_until_interupt
log_message 'status' => 'info', 'message' => 'Ctrl-c to exit'
begin
while true
loop do
sleep 1
end
rescue Interrupt
Expand Down Expand Up @@ -75,7 +73,7 @@ def load_workflow(filename)
connector_settings = configatron.connectors.to_hash
credential_settings = configatron.credentials.to_hash
runtime = Runtime.new(connector_settings, credential_settings)
runtime.logger = self.method(:log_message)
runtime.logger = method(:log_message)
rescue => ex
message = "Couldn't setup workflow process for #{workflow_filename}"
exception message, ex
Expand Down Expand Up @@ -111,4 +109,4 @@ def log_message(message_info)
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/factor.rb
Expand Up @@ -19,4 +19,4 @@
c.when_called Factor::Commands::Workflow, :server
end

alias_command 's', 'server'
alias_command 's', 'server'
14 changes: 5 additions & 9 deletions lib/listener.rb
Expand Up @@ -4,10 +4,8 @@
require 'websocket_manager'

module Factor

# Class Listener for integrating with connector service
class Listener

def initialize(url)
@url = url
end
Expand All @@ -16,14 +14,12 @@ def definition
get("#{@url}/definition")
end

def listener(listener_id, &block)
ws = listen("#{@url}/listeners/#{listener_id}")
ws
def listener(listener_id)
listen("#{@url}/listeners/#{listener_id}")
end

def action(action_id, &block)
ws = listen("#{@url}/actions/#{action_id}")
ws
def action(action_id)
listen("#{@url}/actions/#{action_id}")
end

private
Expand All @@ -45,4 +41,4 @@ def listen(uri_path)
WebSocketManager.new(uri_path)
end
end
end
end
11 changes: 5 additions & 6 deletions lib/runtime.rb
Expand Up @@ -41,17 +41,16 @@ def initialize(connectors, credentials)

def load(workflow_definition)
EM.run do
self.instance_eval(workflow_definition)
instance_eval(workflow_definition)
end
end

def listen(service_id, listener_id, params = {}, &block)

ws = @connectors[service_id.to_sym].listener(listener_id)

handle_on_open(service_id, listener_id, 'Listener', ws, params)

ws.on :close do |event|
ws.on :close do
error 'Listener disconnected'
if @reconnect
warn 'Reconnecting...'
Expand Down Expand Up @@ -103,7 +102,7 @@ def run(service_id, action_id, params = {}, &block)

handle_on_open(service_id, action_id, 'Action', ws, params)

ws.on :error do |event|
ws.on :error do
error 'Connection dropped while calling action'
end

Expand Down Expand Up @@ -134,7 +133,7 @@ def run(service_id, action_id, params = {}, &block)
private

def handle_on_open(service_id, action_id, dsl_type, ws, params)
ws.on :open do |event|
ws.on :open do
params.merge!(@credentials[service_id.to_sym] || {})
success "#{dsl_type.capitalize} '#{service_id}::#{action_id}' called"
ws.send(params.to_json)
Expand Down Expand Up @@ -172,4 +171,4 @@ def log_message(message_info)
@logger.call(message_info) if @logger
end
end
end
end
2 changes: 1 addition & 1 deletion lib/websocket_manager.rb
Expand Up @@ -92,4 +92,4 @@ def connect
end
end
end
end
end
2 changes: 1 addition & 1 deletion spec/workflow_spec.rb
Expand Up @@ -8,4 +8,4 @@

end
end
end
end

0 comments on commit 86ae972

Please sign in to comment.