lib/traka/change.rb in traka-0.0.5 vs lib/traka/change.rb in traka-0.0.6

- old
+ new

@@ -28,16 +28,24 @@ File.open(version_path, "w") do |f| f.write(v.to_s) end end - def staged_changes(opts={}) - opts = {:version => latest_version + 1, + def changes(opts={}) + opts = {:version => nil, :filter => true, :actions => [], :only => []}.merge(opts) + # If version is specified, return only published changes from v onwards. + # Otherwise, return only unstaged changes. + unless opts[:version].is_a?(Range) + opts[:version] = opts[:version] ? + (opts[:version]..latest_version) : + latest_version + 1 + end + c = where(["version #{opts[:version].is_a?(Range) ? "in" : ">="} (?)", opts[:version]]) unless opts[:actions].empty? c = c.where(["action_type in (?)", opts[:actions]]) end @@ -47,21 +55,20 @@ end if opts[:filter] filter_changes(c) else - c + c.all end end private def version_path File.join( Rails.root, "public", "system", "api", "version.txt") end - # Filters out obsolete changes in the given set. For example, # there is no point giving out 4 "update" changes, just one will # suffice. And if you "create" and then "destroy" a record in one # changeset, they should cancel each other out.