Class: Clubhouse::Story

Inherits:
BaseResource show all
Defined in:
lib/clubhouse/story.rb

Instance Attribute Summary

Attributes inherited from BaseResource

#client

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseResource

attributes, attributes_for_create, attributes_for_update, client, delete, find, #initialize, #reload, resource, #save

Constructor Details

This class inherits a constructor from Clubhouse::BaseResource

Class Method Details

.allObject



52
53
54
55
# File 'lib/clubhouse/story.rb', line 52

def all
  raise NotSupportedByAPIError,
    'Use Story.search(..) to return stories matching your search query'
end

.search(attr = {}) ⇒ Object



57
58
59
60
# File 'lib/clubhouse/story.rb', line 57

def search(attr = {})
  payload = client.post("#{endpoint}/search", attr)
  payload.collect {|s| new.update_object_from_payload(s) }
end

Instance Method Details

#add_comment(text) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/clubhouse/story.rb', line 28

def add_comment(text)
  add_resource(:comment) do
    comment = Comment.new(text: text, story_id: id)
    comment.save
    comments << comment
  end
end

#add_task(desc) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/clubhouse/story.rb', line 36

def add_task(desc)
  add_resource(:task) do
    task = Task.new(description: desc, story_id: id)
    task.save
    tasks << task
  end
end

#commentsObject



20
21
22
# File 'lib/clubhouse/story.rb', line 20

def comments
  @_comments ||= Array(@comments).collect {|c| Comment.new.update_object_from_payload(c) }
end

#tasksObject



24
25
26
# File 'lib/clubhouse/story.rb', line 24

def tasks
  @_tasks ||= Array(@tasks).collect {|t| Task.new.update_object_from_payload(t) }
end

#update_object_from_payload(attr = {}) ⇒ Object



44
45
46
47
48
49
# File 'lib/clubhouse/story.rb', line 44

def update_object_from_payload(attr = {})
  super
  instance_variable_set("@_comments", nil)
  instance_variable_set("@_tasks", nil)
  self
end