Skip to content

Commit

Permalink
Add name to Line and Stream to access the parent view;
Browse files Browse the repository at this point in the history
Note: Stream will try to access Line, and Line will access the parent view.

Work relating to #302.
  • Loading branch information
gavinlaking committed Nov 12, 2015
1 parent 9795ead commit ab41103
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/vedeu/models/views/line.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ def eql?(other)
end
alias_method :==, :eql?

# @return [NilClass|String|Symbol]
def name
parent.name if parent
end

# Returns the size of the content in characters without
# formatting.
#
Expand Down
6 changes: 6 additions & 0 deletions lib/vedeu/models/views/stream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def chars

@chars ||= value.chars.map do |char|
member.new(value: char,
name: name,
parent: parent,
colour: colour,
style: style,
Expand Down Expand Up @@ -101,6 +102,11 @@ def eql?(other)
end
alias_method :==, :eql?

# @return [NilClass|String|Symbol]
def name
parent.name if parent
end

# Returns the size of the content in characters without
# formatting.
#
Expand Down
14 changes: 14 additions & 0 deletions test/lib/vedeu/models/views/line_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,20 @@ module Views
end
end

describe '#name' do
subject { instance.name }

context 'when a parent is set' do
it { subject.must_equal('Vedeu::Line') }
end

context 'when a parent is not set' do
let(:parent) {}

it { subject.must_equal(nil) }
end
end

describe '#size' do
subject { instance.size }

Expand Down
14 changes: 14 additions & 0 deletions test/lib/vedeu/models/views/stream_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,20 @@ module Views
end
end

describe '#name' do
subject { instance.name }

context 'when a parent is set' do
it { subject.must_equal('Vedeu::Views::Stream') }
end

context 'when a parent is not set' do
let(:parent) {}

it { subject.must_equal(nil) }
end
end

describe '#size' do
subject { instance.size }

Expand Down

0 comments on commit ab41103

Please sign in to comment.