platanus 0.0.49 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
- self.removed_at = DateTime.now
61
- self.save!
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
@@ -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
- # # Renders an empty response
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
- # # Renders a regular response
91
- def api_respond_with(*_params)
92
- if _params.last.is_a? Hash
93
- _options = _params.last
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
- # # Renders an error response
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.
@@ -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, "#{tname_single}_will" do
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, "#{tname_single}_is" do
70
+ send :define_method, "#{top_value_prop}_is" do
71
71
  instance_variable_get(last_value_var)
72
72
  end
73
73
 
@@ -1,3 +1,3 @@
1
1
  module Platanus
2
- VERSION = "0.0.49" # 0.1 will come with tests!
2
+ VERSION = "0.1.1" # 0.2 will come with tests!
3
3
  end
data/lib/platanus.rb CHANGED
@@ -7,6 +7,7 @@ require 'platanus/traceable'
7
7
  require 'platanus/layered'
8
8
  require 'platanus/enum'
9
9
  require 'platanus/http_helpers'
10
+ require 'platanus/model_shims'
10
11
 
11
12
  # require 'platanus/onetime'
12
13
  # require 'platanus/gcontroller'
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.0.49
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: 2012-12-26 00:00:00.000000000 Z
12
+ date: 2013-02-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: multi_json