Skip to content

Commit ca977f2

Browse files
authored
Refact BrDanfe::Logo::Config to no implement OpenStruct (#233)
1 parent 8e96e3c commit ca977f2

File tree

5 files changed

+12
-26
lines changed

5 files changed

+12
-26
lines changed

Gemfile.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
br_danfe (0.19.0)
4+
br_danfe (0.20.0)
55
barby (= 0.6.9)
66
br_documents (>= 0.1.3)
77
i18n (>= 0.8.6)

lib/br_danfe.rb

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
require 'barby/outputter/prawn_outputter'
77
require 'nokogiri'
88
require 'yaml'
9-
require 'ostruct'
109
require 'i18n'
1110
require 'br_documents'
1211

lib/br_danfe/logo_config.rb

+4-15
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,11 @@
11
module BrDanfe
22
module Logo
3-
class Config < OpenStruct
4-
DEFAULTOPTIONS = { logo: '', logo_dimensions: {} }.freeze
3+
class Config
4+
attr_accessor :logo, :logo_dimensions
55

66
def initialize(new_options = {})
7-
options = DEFAULTOPTIONS.merge(config_yaml_load)
8-
super options.merge(new_options)
9-
end
10-
11-
private
12-
13-
def file
14-
File.exist?('config/br_danfe.yml') ? File.open('config/br_danfe.yml').read : ''
15-
end
16-
17-
def config_yaml_load
18-
@file_read = YAML.safe_load(file)
19-
@file_read ? (@file_read['br_danfe'] || {})['options'] : {}
7+
@logo = new_options[:logo] || ''
8+
@logo_dimensions = new_options[:logo_dimensions] || {}
209
end
2110
end
2211
end

lib/br_danfe/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module BrDanfe
2-
VERSION = '0.19.0'.freeze
2+
VERSION = '0.20.0'.freeze
33
end

spec/br_danfe/logo_config_spec.rb

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
require 'spec_helper'
22

33
describe BrDanfe::Logo::Config do
4-
let(:options) { {} }
5-
6-
subject { described_class.new options }
4+
subject { described_class.new({}) }
75

86
it 'returns the default config set in the code' do
9-
expect(subject.logo).to eq('')
10-
expect(subject.logo_dimensions).to eq({})
7+
expect(subject.logo).to eql ''
8+
expect(subject.logo_dimensions).to eql({})
119
end
1210

1311
context 'when there are custom options' do
14-
let(:options) { { logo: '/fake/path/file.png', logo_dimensions: { width: 50, height: 50 } } }
12+
subject { described_class.new({ logo: '/fake/path/file.png', logo_dimensions: { width: 50, height: 50 } }) }
1513

1614
it 'returns the config set in params' do
17-
expect(subject.logo).to eq('/fake/path/file.png')
18-
expect(subject.logo_dimensions).to eq(width: 50, height: 50)
15+
expect(subject.logo).to eql '/fake/path/file.png'
16+
expect(subject.logo_dimensions).to eql width: 50, height: 50
1917
end
2018
end
2119
end

0 commit comments

Comments
 (0)