Class: Pwl::EntryMapper
- Inherits:
-
Object
- Object
- Pwl::EntryMapper
- Defined in:
- lib/pwl/entry_mapper.rb
Overview
DataMapper that maps an Entry from and to JSON
Constant Summary collapse
- ATTRIBUTES =
%w[uuid name password]
Class Method Summary collapse
Class Method Details
.from_json(str) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/pwl/entry_mapper.rb', line 10 def from_json(str) json = JSON(str, :symbolize_names => true) Entry.new.tap do |entry| ATTRIBUTES.each do |attr| entry.send("#{attr}=", json[attr.to_sym]) end end end |
.to_json(entry) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/pwl/entry_mapper.rb', line 20 def to_json(entry) entry.validate! result = {} ATTRIBUTES.each do |attr| result.store(attr.to_sym, entry.send(attr)) end result.to_json end |