artifacts 2.0.3 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,37 +7,66 @@ class Artifacts
7
7
  type :creator, String
8
8
  type :summary, String
9
9
 
10
+ type :priority, Integer, :default => 0
11
+
10
12
  type :created, Time, :default => Time.now
11
13
  type :closed, [NilClass,Time], :default => nil
12
14
 
13
- has :dependee_references, ArtifactArtifact, ArtifactArtifact => :dependee
14
- has :dependant_references, ArtifactArtifact, ArtifactArtifact => :dependant
15
+ has :depended_on_by_references, ArtifactArtifact, ArtifactArtifact => :depended_on_by
16
+ has :depends_on_references, ArtifactArtifact, ArtifactArtifact => :depends_on
15
17
 
16
18
  has :tags, Tag, :many_to_many => true
17
19
  has :comments, Comment
18
20
  init :creator, :summary
19
21
 
20
- def dependants
21
- dependee_references.map{|n|n.dependant}
22
+ def self.priority_width
23
+ all.map{|n|n.priority.to_s}.sort{|a,b|a.length <=> b.length}.first.length
24
+ end
25
+
26
+ def open?
27
+ closed == nil
28
+ end
29
+
30
+ def closed?
31
+ closed != nil
32
+ end
33
+
34
+ def <=>( other )
35
+ offset = ( closed? ^ other.closed? ) ? ( closed? ? 1 : -1 ) : 0
36
+ offset = other.open_depended_on_by.size <=> self.open_depended_on_by.size if offset == 0
37
+ offset = self.id <=> other.id if offset == 0
38
+ offset
39
+ end
40
+
41
+ def open_depends_on
42
+ depends_on.select{|n|!n.closed}
43
+ end
44
+
45
+ def depends_on
46
+ depended_on_by_references.map{|n|n.depends_on}
47
+ end
48
+
49
+ def open_depended_on_by
50
+ depended_on_by.select{|n|!n.closed}
22
51
  end
23
52
 
24
- def dependees
25
- dependant_references.map{|n|n.dependee}
53
+ def depended_on_by
54
+ depends_on_references.map{|n|n.depended_on_by}
26
55
  end
27
56
 
28
57
  def to_s
29
- "%#{YAML_Model.next_oid.to_s.length}d #{summary}"%[id]
58
+ "%#{YAML_Model.next_oid.to_s.length}d #{depended_on_by.size > 0 ? 'd' : '-'}#{depends_on.size > 0 ? 'D' : '-'}#{comments.size > 0 ? 'c' : '-'} %#{self.class.priority_width}s #{summary}"%[id,closed ? 'X' : ( priority == 0 ? '' : priority.to_s )]
30
59
  end
31
60
 
32
61
  def inspect
33
62
  indentation = ' '*(YAML_Model.next_oid.to_s.length + 1)
34
63
  "#{to_s}\n" +
35
- indentation + 'created : ' + created.to_s + "\n" +
36
- ( closed ? (indentation + 'closed : ' + closed.to_s + "\n" ) : '' ) +
37
- ( tags.size > 0 ? (indentation + 'tags : [' + tags.map{|n|n.name}.join(',') + "]\n" ) : '' ) +
38
- ( dependees.size > 0 ? (indentation + 'dependees : [' + dependees.map{|n|n.id}.join(',') + "]\n" ) : '' ) +
39
- ( dependants.size > 0 ? (indentation + 'dependants : [' + dependants.map{|n|n.id}.join(',') + "]\n" ) : '' ) +
40
- ( comments.size > 0 ? (indentation + "comments :\n" + comments.join("\n")) : '' )
64
+ indentation + 'created : ' + created.to_s + "\n" +
65
+ ( closed ? (indentation + 'closed : ' + closed.to_s + "\n" ) : '' ) +
66
+ ( tags.size > 0 ? (indentation + 'tags : [' + tags.map{|n|n.name}.join(',') + "]\n" ) : '' ) +
67
+ ( depended_on_by.size > 0 ? (indentation + 'depended on by : [' + depended_on_by.map{|n|n.id}.join(',') + "]\n" ) : '' ) +
68
+ ( depends_on.size > 0 ? (indentation + 'depends on : [' + depends_on.map{|n|n.id}.join(',') + "]\n" ) : '' ) +
69
+ ( comments.size > 0 ? (indentation + "comments :\n" + comments.join("\n")) : '' )
41
70
  end
42
71
 
43
72
  end
@@ -1,8 +1,8 @@
1
1
  class Artifacts
2
2
  Artifact ||= Class.new( YAML_Model )
3
3
  class ArtifactArtifact < YAML_Model
4
- type :dependee, Artifact
5
- type :dependant, Artifact
6
- init :dependee, :dependant
4
+ type :depended_on_by, Artifact
5
+ type :depends_on, Artifact
6
+ init :depended_on_by, :depends_on
7
7
  end
8
8
  end
@@ -33,6 +33,8 @@ class Artifacts
33
33
 
34
34
  @closed = false
35
35
  @open = true
36
+ @verbose = false
37
+ @dependants = false
36
38
 
37
39
  unless args.select{|n|n=~/^(?:-c|--closed)$/}.empty?
38
40
  @closed = true
@@ -54,7 +56,23 @@ class Artifacts
54
56
  args.delete( '--verbose' )
55
57
  end
56
58
 
59
+ unless args.select{|n|n=~/^(?:-d|--dependants)$/}.empty?
60
+ @dependants = true
61
+ args.delete( '-d' )
62
+ args.delete( '--dependants' )
63
+ end
64
+
65
+ unless args.select{|n|n=~/^(?:-l|--limit)$/}.empty?
66
+ idx = args.index( '-l' )
67
+ idx ||= args.index( '--limit' )
68
+ args.delete_at( idx )
69
+ @limit = args.delete_at( idx ).to_i
70
+ end
71
+
72
+ @limit = ( @verbose ? 3 : 10 ) if @limit.to_i < 1
73
+
57
74
  @artifacts = []
75
+ @tags = []
58
76
  any_artifacts_given = false
59
77
  while match = args.first && args.first.match( /^(?:(\d+)|#(#{Tag::VALID_NAME}))$/ )
60
78
  any_artifacts_given = true
@@ -62,22 +80,30 @@ class Artifacts
62
80
  @artifacts << Artifact[ args.shift.to_i ]
63
81
  elsif match[2]
64
82
  args.shift
83
+ @tags << match[2]
65
84
  tag = Tag.select{|n|n.name == match[2]}.first
66
85
  @artifacts << tag.artifacts if tag
67
86
  end
68
87
  end
88
+
69
89
  @artifacts.flatten!
70
90
  @artifacts.uniq!
71
91
 
92
+ @tags.flatten!
93
+ @tags.uniq!
94
+
72
95
  @artifacts = Artifact.all unless any_artifacts_given
73
96
 
74
97
  @artifacts = @artifacts.select do |artifact|
75
- ( @open && !artifact.closed ) ||
76
- ( @closed && artifact.closed )
98
+ ( ( @open && !artifact.closed ) ||
99
+ ( @closed && artifact.closed ) ) &&
100
+ ( @dependants || artifact.open_depends_on.size == 0 )
77
101
  end
78
102
 
103
+ @artifacts.sort!
104
+
79
105
  command = args.shift
80
- command ||= :help
106
+ command ||= :list
81
107
 
82
108
  send( command.to_sym, *args )
83
109
  end
@@ -101,27 +127,35 @@ class Artifacts
101
127
  help_command :list, 'List artifacts'
102
128
  end
103
129
 
104
- def self.default_list_filter( list )
105
- list.select{|a|a.closed == nil && a.dependees.size == 0}
106
- end
107
-
108
130
  def list
109
- @artifacts.each do |artifact|
131
+ @limit = @artifacts.size if @limit > @artifacts.size
132
+ @limit.times do
133
+ artifact = @artifacts.shift
110
134
  puts artifact.send( @verbose ? :inspect : :to_s )
111
135
  end
136
+ puts "... #{@artifacts.size} more ..." unless @artifacts.empty?
112
137
  end
113
138
 
114
139
  def create( *args )
115
140
  artifact = Artifact.create( Artifacts.username, args.join(' ') )
116
141
  puts "Created artifact #{artifact.id}."
142
+ @artifacts = [artifact]
143
+ tag( *@tags )
117
144
  end
118
145
 
119
146
  def close
120
147
  @artifacts.each do |artifact|
121
148
  artifact.closed = Time.now
149
+ puts "Closed: #{artifact}"
150
+ end
151
+ end
152
+
153
+ def priority( priority )
154
+ priority = priority.to_i
155
+ @artifacts.each do |artifact|
156
+ artifact.priority = priority
157
+ puts "Priority changed to #{priority} for: #{artifact}"
122
158
  end
123
- puts "Closed artifacts:"
124
- list
125
159
  end
126
160
 
127
161
  def version
@@ -132,10 +166,11 @@ class Artifacts
132
166
 
133
167
  def depends( *args )
134
168
  args.shift if args.first == 'on' # optional syntax sugar
135
- dependees = args.map{|id|Artifact[id.to_i]}
169
+ depends_on_list = args.map{|id|Artifact[id.to_i]}
136
170
  @artifacts.each do |artifact|
137
- dependees.each do |dependee|
138
- ArtifactArtifact.create( dependee, artifact )
171
+ depends_on_list.each do |depends_on|
172
+ ArtifactArtifact.create( artifact, depends_on )
173
+ puts "Artifact [#{artifact.id}] now depends on artifact [#{depends_on.id}]"
139
174
  end
140
175
  end
141
176
  end
@@ -145,6 +180,7 @@ class Artifacts
145
180
  tag = Tag.select{|n|n.name == tag_name}.first
146
181
  tag ||= Tag.create( tag_name )
147
182
  @artifacts.each do |artifact|
183
+ puts "Adding tag \"#{tag.name}\" to #{artifact}"
148
184
  artifact.add_tag( tag )
149
185
  end
150
186
  end
@@ -154,6 +190,7 @@ class Artifacts
154
190
  args.each do |tag_name|
155
191
  tag = Tag.select{|n|n.name == tag_name}.first
156
192
  @artifacts.each do |artifact|
193
+ puts "Removing tag \"#{tag.name}\" from #{artifact}"
157
194
  artifact.remove_tag( tag )
158
195
  end
159
196
  end
@@ -1,3 +1,3 @@
1
1
  class Artifacts
2
- VERSION = "2.0.3"
2
+ VERSION = "2.1.0"
3
3
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 2
7
+ - 1
7
8
  - 0
8
- - 3
9
- version: 2.0.3
9
+ version: 2.1.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Clive Crous
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-02-16 00:00:00 +02:00
17
+ date: 2011-02-17 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -114,7 +114,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - ">="
116
116
  - !ruby/object:Gem::Version
117
- hash: 716821293
117
+ hash: -715623571
118
118
  segments:
119
119
  - 0
120
120
  version: "0"
@@ -123,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
123
  requirements:
124
124
  - - ">="
125
125
  - !ruby/object:Gem::Version
126
- hash: 716821293
126
+ hash: -715623571
127
127
  segments:
128
128
  - 0
129
129
  version: "0"