-
Notifications
You must be signed in to change notification settings - Fork 897
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move apply_dialog_settings logic into DialogProperties class
- Loading branch information
1 parent
12b109c
commit e00b17b
Showing
3 changed files
with
78 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
class Service | ||
class DialogProperties | ||
def initialize(options) | ||
@attributes = {} | ||
@options = options || {} | ||
end | ||
|
||
def self.parse(options) | ||
new(options).parse | ||
end | ||
|
||
def parse | ||
@attributes.tap { parse_options } | ||
end | ||
|
||
private | ||
|
||
def parse_options | ||
%w(name description).each do |field_name| | ||
dialog_field_name = "dialog_service_#{field_name}" | ||
dialog_field_value = @options[dialog_field_name] | ||
parse_value(field_name, dialog_field_name, dialog_field_value) if @options.key?(dialog_field_name) | ||
end | ||
end | ||
|
||
def parse_value(field_name, dialog_field_name, dialog_field_value) | ||
send(field_name, dialog_field_value) if @options.key?(dialog_field_name) | ||
rescue StandardError => err | ||
$log.error("Error setting key [#{dialog_field_name}] with value [#{dialog_field_value.inspect}] error: [#{err}]") | ||
end | ||
|
||
def name(value) | ||
@attributes[:name] = value if value.present? | ||
end | ||
|
||
def description(value) | ||
@attributes[:description] = value if value.present? | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
describe Service::DialogProperties do | ||
it 'with a nil parameter' do | ||
options = nil | ||
expect(described_class.parse(options)).to eq({}) | ||
end | ||
|
||
it 'with an empty hash' do | ||
options = {} | ||
expect(described_class.parse(options)).to eq({}) | ||
end | ||
|
||
context 'name' do | ||
it 'with an empty name' do | ||
options = {'dialog_service_name' => ' '} | ||
expect(described_class.parse(options)).to eq({}) | ||
end | ||
|
||
it 'with option name' do | ||
options = {'dialog_service_name' => 'name from dialog'} | ||
expect(described_class.parse(options)).to eq(:name => 'name from dialog') | ||
end | ||
end | ||
|
||
context 'description' do | ||
it 'with an empty description' do | ||
options = {'dialog_service_description' => ' '} | ||
expect(described_class.parse(options)).to eq({}) | ||
end | ||
|
||
it 'with option description' do | ||
options = {'dialog_service_description' => 'test description from dialog'} | ||
expect(described_class.parse(options)).to eq(:description => 'test description from dialog') | ||
end | ||
end | ||
end |