lib/traka/change.rb in traka-0.0.4 vs lib/traka/change.rb in traka-0.0.5
- old
+ new
@@ -28,24 +28,30 @@
File.open(version_path, "w") do |f|
f.write(v.to_s)
end
end
- def staged_changes(concise=true)
- changes_for_v(latest_version + 1, concise)
- end
+ def staged_changes(opts={})
+ opts = {:version => latest_version + 1,
+ :filter => true,
+ :actions => [],
+ :only => []}.merge(opts)
- def changes_for_v(v, concise=true)
- changes_in_range(v, v, concise)
- end
+ c = where(["version #{opts[:version].is_a?(Range) ? "in" : ">="} (?)", opts[:version]])
- def changes_from(v, concise=true)
- changes_in_range(v, latest_version + 1, concise=true)
- end
+ unless opts[:actions].empty?
+ c = c.where(["action_type in (?)", opts[:actions]])
+ end
- def changes_in_range(from=1, to=latest_version + 1, concise=true)
- c = where(["version >= ? AND version <= ?", from, to])
- concise ? filter_changes(c) : c
+ unless opts[:only].empty?
+ c = c.where(["klass in (?)", opts[:only].map(&:to_s)])
+ end
+
+ if opts[:filter]
+ filter_changes(c)
+ else
+ c
+ end
end
private
def version_path