Class: Wutang::Interface
- Inherits:
-
Object
- Object
- Wutang::Interface
- Defined in:
- lib/wutang/interface.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#persistence ⇒ Object
readonly
Returns the value of attribute persistence.
Instance Method Summary collapse
- #create(attributes) ⇒ Object
- #entries ⇒ Object
- #find(entry_id) ⇒ Object
-
#initialize ⇒ Interface
constructor
A new instance of Interface.
- #search(criteria) ⇒ Object
- #update(entry, updates) ⇒ Object
Constructor Details
#initialize ⇒ Interface
Returns a new instance of Interface.
5 6 7 |
# File 'lib/wutang/interface.rb', line 5 def initialize @config = Config.new.attributes end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
3 4 5 |
# File 'lib/wutang/interface.rb', line 3 def config @config end |
#persistence ⇒ Object (readonly)
Returns the value of attribute persistence.
3 4 5 |
# File 'lib/wutang/interface.rb', line 3 def persistence @persistence end |
Instance Method Details
#create(attributes) ⇒ Object
17 18 19 20 21 |
# File 'lib/wutang/interface.rb', line 17 def create(attributes) Entry.new(attributes, Persistence.generate_filename).tap do |entry| persistence.write entry.path, entry.as_json end end |
#entries ⇒ Object
13 14 15 |
# File 'lib/wutang/interface.rb', line 13 def entries persistence.all end |
#find(entry_id) ⇒ Object
37 38 39 |
# File 'lib/wutang/interface.rb', line 37 def find(entry_id) entries.detect { |entry| entry.path == entry_id } end |
#search(criteria) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/wutang/interface.rb', line 30 def search(criteria) entries.select do |entry| attributes = entry.attributes attributes.keys.any? { |key| attributes[key] =~ /#{criteria}/ } end end |
#update(entry, updates) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/wutang/interface.rb', line 23 def update(entry, updates) entry.tap do entry.attributes.merge! updates persistence.write entry.path, entry.as_json end end |