Class: Peaty::Story

Inherits:
Base show all
Defined in:
lib/peaty/story.rb

Constant Summary

Constants inherited from Base

Base::FILTERS

Instance Attribute Summary

Attributes inherited from Base

#attributes, #connection, #error

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

all, build, #error?, filter_options, find, find_by_id, first, #id, #initialize, #method_missing, #new_record?, parse, #respond_to?, #save, with_connection

Constructor Details

This class inherits a constructor from Peaty::Base

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Peaty::Base

Class Method Details

.collection_path(options = {}) ⇒ Object



47
48
49
# File 'lib/peaty/story.rb', line 47

def collection_path(options = {})
  "/projects/%i/stories" % options[:project_id].to_i
end

.elementObject



44
45
46
# File 'lib/peaty/story.rb', line 44

def element
  "story"
end

.member_path(id, options = {}) ⇒ Object



50
51
52
# File 'lib/peaty/story.rb', line 50

def member_path(id, options = {})
  "/projects/%i/stories/%i" % [options[:project_id].to_i, id]
end

.move_path(id, options = {}) ⇒ Object



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

def move_path(id, options = {})
  "/projects/%i/stories/%i/moves?move[move]=%s&move[target]=%i" % [options[:project_id].to_i, id, options[:type], options[:target_id].to_i]
end

.releases(options = {}) ⇒ Object

Filters



59
60
61
# File 'lib/peaty/story.rb', line 59

def releases(options = {})
  self.filter(:type => :release)
end

Instance Method Details

#estimateObject

chores, bugs, releases may or may not have estimates



11
12
13
# File 'lib/peaty/story.rb', line 11

def estimate
  self.attributes["estimate"].to_i
end

#move(options) ⇒ Object

Moves a story before or after another story

story1.move(:before => story2)
story2.move(:after => story1)


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/peaty/story.rb', line 23

def move(options)
  @error = nil

  move_options = { :project_id => project_id }
  if options[:before]
    move_options.merge!({ :type => :before, :target_id => options[:before].id })
  elsif options[:after]
    move_options.merge!({ :type => :after, :target_id => options[:after].id })
  else
    raise ArgumentError, "Must specify :before => story or :after => story"
  end

  self.connection[self.class.move_path(id, move_options)].post("").body

  self
rescue RestClient::UnprocessableEntity => e
  @error = JSON.parse(XmlToJson.transform(e.response.body))["message"]
  false
end

#projectObject



15
16
17
# File 'lib/peaty/story.rb', line 15

def project
  Project.with_connection(self.class.connection).find(self.project_id)
end

#story_typeObject Also known as: type



5
6
7
# File 'lib/peaty/story.rb', line 5

def story_type
  self.attributes["story_type"].to_sym if story_type?
end