Skip to content

Commit

Permalink
Add attribute accessor for .pluck
Browse files Browse the repository at this point in the history
Fixes #57
  • Loading branch information
esmarkowski committed Mar 11, 2024
1 parent 4db16d3 commit 6e5b448
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/stretchy/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ def inspect
"#<#{self.class.name} #{attributes.map { |k,v| "#{k}: #{v.blank? ? 'nil' : v}" }.join(', ')}>"
end

def [](attribute)
self.send(attribute)
end

class_methods do

Expand Down
9 changes: 9 additions & 0 deletions spec/stretchy/record_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,16 @@
expect(described_class.default_size).to eq(100)
end

end
end

context 'attributes' do

it 'accesses attributes' do
expect(described_class.new(title: "hello")[:title]).to eq("hello")
end
it 'plucks' do
expect(described_class.all.pluck(:title)).to be_a(Array)
end
end

Expand Down

0 comments on commit 6e5b448

Please sign in to comment.