artisan-memory-repository 0.0.3 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,23 +2,10 @@ module ArtisanMemoryRepository
2
2
 
3
3
  module BaseRepository
4
4
  def save(object)
5
- clone = object.dup
6
-
7
- if clone.id
8
- records[clone.id] = clone
9
- else
10
- clone.id = records.size + 1
11
- records[clone.id] = clone
12
- end
13
-
14
- return clone
5
+ object.id = records.size + 1 if object.id.nil?
6
+ records[object.id] = object
15
7
  end
16
8
 
17
- #def create!(attrs = {})
18
- # project = model_class.new(attrs)
19
- # self.save(project)
20
- #end
21
-
22
9
  def create(attrs = {})
23
10
  project = model_class.new(attrs)
24
11
  self.save(project)
@@ -17,15 +17,16 @@ module ArtisanMemoryRepository
17
17
  create(attributes.merge({:type => "IterationChange"}))
18
18
  end
19
19
 
20
-
21
20
  def create_story_change(attributes = {})
22
21
  create(attributes.merge({:type => "StoryChange"}))
23
22
  end
24
23
 
25
-
26
24
  def find_all_by_project_id(project_id)
27
25
  records.values.find_all {|r| r.project_id == project_id}.sort_by(&:created_at).reverse
28
26
  end
29
27
 
28
+ def find_range_by_project_id(project_id, starts_at, ends_at)
29
+ find_all_by_project_id(project_id)[starts_at..ends_at]
30
+ end
30
31
  end
31
32
  end
@@ -1,9 +1,10 @@
1
1
  module ArtisanMemoryRepository
2
2
  class Base
3
+ @@next_id = 1
3
4
  def initialize(options = {})
4
5
  self.class._collections.each {|field| set(field, [])}
5
6
  options.each { |key, value| set(key, value) }
6
- set(:id, random_int) if saves?
7
+ set(:id, next_id) if saves?
7
8
  self.init
8
9
  end
9
10
 
@@ -78,8 +79,8 @@ module ArtisanMemoryRepository
78
79
 
79
80
  private
80
81
 
81
- def random_int
82
- return (Time.now.to_i + rand(1000))
82
+ def next_id
83
+ @@next_id += 1
83
84
  end
84
85
  end
85
86
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: artisan-memory-repository
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.11
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-13 00:00:00.000000000 Z
12
+ date: 2013-01-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel
@@ -73,7 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
73
  version: '0'
74
74
  requirements: []
75
75
  rubyforge_project:
76
- rubygems_version: 1.8.21
76
+ rubygems_version: 1.8.24
77
77
  signing_key:
78
78
  specification_version: 3
79
79
  summary: Artisan Memory Repository