Class: Wutang::Interface

Inherits:
Object
  • Object
show all
Defined in:
lib/wutang/interface.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeInterface

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

#configObject (readonly)

Returns the value of attribute config.



3
4
5
# File 'lib/wutang/interface.rb', line 3

def config
  @config
end

#persistenceObject (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

#entriesObject



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