Skip to content

Commit

Permalink
fixed #14
Browse files Browse the repository at this point in the history
Rails Domain now reads the configuration file
  • Loading branch information
arBmind committed Feb 14, 2015
1 parent ebd241a commit ab9fff7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
39 changes: 31 additions & 8 deletions active_event/lib/active_event/domain.rb
Expand Up @@ -21,8 +21,7 @@ module Domain

def initialize(*args)
super
# DRb.start_service # should not be necessary
self.server = DRbObject.new_with_uri self.class.server_uri
self.server = DRbObject.new_with_uri drb_server_uri
end

def run_command(command)
Expand All @@ -36,19 +35,43 @@ def run_command(command)

attr_accessor :server

def drb_server_uri
self.class.drb_server_uri || URI::Generic.build(options[:drb_server]).to_s
end

def options
@options ||= parse_options
end

def config_file
self.class.config_file || File.join(Rails.root, 'config', 'disco.yml')
end

def default_options
{
drb_server: {
scheme: 'druby',
hostname: '127.0.0.1',
port: 8787,
},
}
end

def parse_options
options = default_options
options.merge! YAML.load_file(config_file)[Rails.env].deep_symbolize_keys! unless config_file.blank?
end

module ClassMethods
def run_command(command)
instance.run_command command
end

attr_accessor :server_uri

def self.extended(base)
base.server_uri = 'druby://127.0.0.1:8787'
end
attr_accessor :drb_server_uri
attr_accessor :config_file

def set_config(protocol = 'druby', host = 'localhost', port = 8787)
self.server_uri = "#{protocol}://#{host}:#{port}"
self.drb_server_uri = "#{protocol}://#{host}:#{port}"
end
end
end
Expand Down
3 changes: 2 additions & 1 deletion active_event/spec/lib/domain_spec.rb
Expand Up @@ -12,7 +12,8 @@ class TestDomain
end

it 'sends command over instance' do
expect(DRbObject).to receive(:new_with_uri).with(TestDomain.server_uri).and_return(@drb_object)
TestDomain.set_config('dummy')
expect(DRbObject).to receive(:new_with_uri).with(TestDomain.drb_server_uri).and_return(@drb_object)
expect(@command).to receive(:valid?).and_return(true)
expect(@drb_object).to receive(:run_command).with(@command)
TestDomain.run_command(@command)
Expand Down

0 comments on commit ab9fff7

Please sign in to comment.