platanus 0.0.49 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/platanus/activable.rb +17 -4
- data/lib/platanus/api_base.rb +7 -29
- data/lib/platanus/stacked2.rb +2 -2
- data/lib/platanus/version.rb +1 -1
- data/lib/platanus.rb +1 -0
- metadata +2 -2
data/lib/platanus/activable.rb
CHANGED
@@ -42,13 +42,26 @@ module Platanus
|
|
42
42
|
self.removed_at.nil?
|
43
43
|
end
|
44
44
|
|
45
|
+
# Clones current object and then removes it.
|
46
|
+
def replace!
|
47
|
+
# self.class.transaction do
|
48
|
+
# clone = self.class.new
|
49
|
+
# self.attributes.each do |key, value|
|
50
|
+
# next if ['id','created_at','removed_at'].include? key
|
51
|
+
# clone.send(:write_attribute, key, value)
|
52
|
+
# end
|
53
|
+
# yield
|
54
|
+
# clone.save!
|
55
|
+
# self.remove!
|
56
|
+
# return clone
|
57
|
+
# end
|
58
|
+
end
|
59
|
+
|
45
60
|
# Deactivates a single record.
|
46
61
|
def remove!
|
47
62
|
self.transaction do
|
48
63
|
run_callbacks :remove do
|
49
64
|
|
50
|
-
# TODO: disable update callbacks and validations!
|
51
|
-
|
52
65
|
# Retrieve dependant properties and remove them.
|
53
66
|
self.class.reflect_on_all_associations.select do |assoc|
|
54
67
|
if assoc.options[:dependent] == :destroy
|
@@ -57,8 +70,8 @@ module Platanus
|
|
57
70
|
end
|
58
71
|
end
|
59
72
|
|
60
|
-
|
61
|
-
self.
|
73
|
+
# Use update column to prevent update callbacks from being ran.
|
74
|
+
self.update_column(:removed_at, DateTime.now)
|
62
75
|
end
|
63
76
|
end
|
64
77
|
end
|
data/lib/platanus/api_base.rb
CHANGED
@@ -52,23 +52,6 @@ module Platanus
|
|
52
52
|
|
53
53
|
module ClassMethods
|
54
54
|
|
55
|
-
# # Enables dumb object wrapping
|
56
|
-
#
|
57
|
-
# When enabled, every request parameter is wrapped in a user defined key.
|
58
|
-
# You should disable default parameter wrapping when using this.
|
59
|
-
# (look at wrap_parameter.rb file for more information on how to disable parameter wrapping)
|
60
|
-
#
|
61
|
-
# @param [Symbol] _key Params key to store parameters in (defaults to :object)
|
62
|
-
#
|
63
|
-
def dumb_wrapping(_key=:object)
|
64
|
-
self.before_filter do
|
65
|
-
# Disable magic parameter wrapping (at env) and use 'object' key to hold
|
66
|
-
# incomming request parameters.
|
67
|
-
return if request.headers['HTTP_USER_AGENT'] == 'Rails Testing'
|
68
|
-
params[:object] = request.request_parameters
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
55
|
# # Enables cors
|
73
56
|
def enable_cors
|
74
57
|
# TODO: maybe cors support should be implemented as a middleware.
|
@@ -81,27 +64,22 @@ module Platanus
|
|
81
64
|
|
82
65
|
module InstanceMethods
|
83
66
|
|
84
|
-
|
67
|
+
## Renders an empty response
|
68
|
+
#
|
85
69
|
def api_respond_empty(_options={})
|
86
70
|
_options[:json] = {}
|
87
71
|
api_respond_with(_options)
|
88
72
|
end
|
89
73
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
_params = _params[0...-1]
|
95
|
-
else
|
96
|
-
_options = {}
|
97
|
-
end
|
98
|
-
|
99
|
-
respond_with(*_params) do |format|
|
74
|
+
## Renders a regular response
|
75
|
+
#
|
76
|
+
def api_respond_with(_resource, _options={})
|
77
|
+
respond_with(_resource) do |format|
|
100
78
|
format.json { render _options }
|
101
79
|
end
|
102
80
|
end
|
103
81
|
|
104
|
-
|
82
|
+
## Renders an error response
|
105
83
|
#
|
106
84
|
# @param [String, Fixnum] _status Response error code.
|
107
85
|
# @param [object] _error_obj Error object to serialize in response.
|
data/lib/platanus/stacked2.rb
CHANGED
@@ -60,14 +60,14 @@ module Platanus
|
|
60
60
|
|
61
61
|
# When called inside callbacks, returns the new value being put at top of the stack.
|
62
62
|
new_value_var = "@_stacked_#{tname}_new"
|
63
|
-
send :define_method, "#{
|
63
|
+
send :define_method, "#{top_value_prop}_will" do
|
64
64
|
instance_variable_get(new_value_var)
|
65
65
|
end
|
66
66
|
|
67
67
|
# When called inside callbacks, will return the top value unless a new value is
|
68
68
|
# being pushed, in that case it returns the new value
|
69
69
|
last_value_var = "@_stacked_#{tname}_last"
|
70
|
-
send :define_method, "#{
|
70
|
+
send :define_method, "#{top_value_prop}_is" do
|
71
71
|
instance_variable_get(last_value_var)
|
72
72
|
end
|
73
73
|
|
data/lib/platanus/version.rb
CHANGED
data/lib/platanus.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: platanus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.1
|
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:
|
12
|
+
date: 2013-02-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: multi_json
|