Skip to content

Commit

Permalink
Latest version including dirty tracking and caching disabling in subc…
Browse files Browse the repository at this point in the history
…lasses
  • Loading branch information
andyjeffries committed Apr 27, 2017
1 parent 7f16604 commit a98f404
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog

## 1.3.34

Feature:

- Added ActiveRecord/Mongoid style dirty/changed tracking methods (thanks to eshork for the PR)

Bugfix:

- Now can disable caching on subclasses after being enabled on a parent (thanks to yujideveloper for the PR)

## 1.3.33

Feature:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,7 @@ end

* The above examples specifically showed PATCH methods, but this is also available for POST and PUT methods for flexibility purposes (even though they break typical REST methodology).
* This logic is currently evaluated before Required Parameters, so it is possible to ensure that requirements are met by some clever usage.
- Ie, if a method is `:requires => [:active], :only_changed => {active: false}` then `active` will always have a value and would always pass the `:requires` directive (so you need to be very careful because the answer may end up being `nil` if you didn't specifically set it).
- This means that if a method is `:requires => [:active], :only_changed => {active: false}` then `active` will always have a value and would always pass the `:requires` directive (so you need to be very careful because the answer may end up being `nil` if you didn't specifically set it).

### HTTP/Parse Error Handling

Expand Down
12 changes: 5 additions & 7 deletions lib/flexirest/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -247,22 +247,22 @@ def prepare_params

# Evaluate :only_changed
if @method[:options][:only_changed]
if http_method == :post or http_method == :put or http_method == :patch then
if http_method == :post or http_method == :put or http_method == :patch
# we only ever mess with @post_params in here, because @get_params will/should never match our method criteria
if @method[:options][:only_changed].is_a? Hash then
if @method[:options][:only_changed].is_a? Hash
# only include the listed attributes marked 'true' when they are changed; attributed marked false are always included
newPostHash = {}
@method[:options][:only_changed].each_pair do |changed_attr_k,changed_attr_v|
if changed_attr_v == false or @object.changes.has_key? changed_attr_k.to_sym then
if changed_attr_v == false or @object.changes.has_key? changed_attr_k.to_sym
newPostHash[changed_attr_k.to_sym] = @object[changed_attr_k.to_sym]
end
end
@post_params = newPostHash
elsif @method[:options][:only_changed].is_a? Array then
elsif @method[:options][:only_changed].is_a? Array
# only send these listed attributes, and only if they are changed
newPostHash = {}
@method[:options][:only_changed].each do |changed_attr|
if @object.changes.has_key? changed_attr.to_sym then
if @object.changes.has_key? changed_attr.to_sym
newPostHash[changed_attr.to_sym] = @object[changed_attr.to_sym]
end
end
Expand All @@ -276,8 +276,6 @@ def prepare_params
@post_params = newPostHash
end
end
else
# did not contain only_changed
end

if @method[:options][:requires]
Expand Down

0 comments on commit a98f404

Please sign in to comment.