hammock 0.2.23 → 0.2.24

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,10 @@
1
+ == 0.2.24 2009-05-05
2
+ Removed two unused methods from active_record patches.
3
+ Renamed find_with_deleted to find_with_destroyed in #find_or_new_with, for acts_as_paranoid -> is_paranoid.
4
+ public_scope and empty_scope now optionally accept an (ignored) account.
5
+ Add exception handling to #mdl, to return nil on nonexistent model instead of raising.
6
+
7
+
1
8
  == 0.2.23 2009-05-04
2
9
  Removed is_paranoid dependency (it'll be in the Rails app for now).
3
10
 
data/hammock.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{hammock}
5
- s.version = "0.2.23"
5
+ s.version = "0.2.24"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Ben Hoskings"]
9
- s.date = %q{2009-05-04}
9
+ s.date = %q{2009-05-05}
10
10
  s.description = %q{Hammock is a Rails plugin that eliminates redundant code in a very RESTful manner. It does this in lots in lots of different places, but in one manner: it encourages specification in place of implementation.
11
11
 
12
12
 
@@ -87,7 +87,7 @@ module Hammock
87
87
  }
88
88
  end
89
89
 
90
- def public_scope account
90
+ def public_scope account = nil
91
91
  if sqlite?
92
92
  lambda {|record| 1 }
93
93
  else
@@ -112,7 +112,7 @@ module Hammock
112
112
  end
113
113
  end
114
114
 
115
- def empty_scope
115
+ def empty_scope account = nil
116
116
  if sqlite?
117
117
  lambda {|record| 0 } # TODO check what this should be
118
118
  else
@@ -62,18 +62,13 @@ module Hammock
62
62
  def record?; false end
63
63
  def resource?; true end
64
64
 
65
- def update_statement set_clause, where_clause
66
- statement = "UPDATE #{table_name} SET #{set_clause} WHERE #{send :sanitize_sql_array, where_clause}"
67
- connection.update statement
68
- end
69
-
70
65
  def reset_cached_column_info
71
66
  reset_column_information
72
67
  subclasses.each &:reset_cached_column_info
73
68
  end
74
69
 
75
70
  def find_or_new_with(find_attributes, create_attributes = {})
76
- finder = respond_to?(:find_with_deleted) ? :find_with_deleted : :find
71
+ finder = respond_to?(:find_with_destroyed) ? :find_with_destroyed : :find
77
72
 
78
73
  if record = send(finder, :first, :conditions => find_attributes.discard(:deleted_at))
79
74
  # Found the record, so we can return it, if:
@@ -81,7 +76,7 @@ module Hammock
81
76
  # (b) it can, but it's not actually deleted,
82
77
  # (c) it is deleted, but we want to find one that's deleted, or
83
78
  # (d) we don't want a deleted record, and undestruction succeeds.
84
- if (finder != :find_with_deleted) || !record.deleted? || create_attributes[:deleted_at] || record.undestroy
79
+ if (finder != :find_with_destroyed) || !record.deleted? || create_attributes[:deleted_at] || record.restore
85
80
  record
86
81
  end
87
82
  else
@@ -153,20 +148,6 @@ module Hammock
153
148
  @new_or_deleted_before_save = new_record? || send_if_respond_to(:deleted?)
154
149
  end
155
150
 
156
- def undestroy
157
- unless new_record?
158
- if frozen?
159
- self.class.find_with_deleted(self.id).undestroy # Re-fetch ourselves and undestroy the thawed copy
160
- else
161
- # We can undestroy
162
- return false if callback(:before_undestroy) == false
163
- result = self.class.update_all ['deleted_at = ?', (self.deleted_at = nil)], ['id = ?', self.id]
164
- callback(:after_undestroy)
165
- self if result != false
166
- end
167
- end
168
- end
169
-
170
151
  # Updates each given attribute to the current time.
171
152
  #
172
153
  # Assumes that each column can accept a +Time+ instance, i.e. that they're all +datetime+ columns or similar.
@@ -20,6 +20,9 @@ module Hammock
20
20
  # The model this controller operates on. Defined as the singularized controller name. For example, for +GelatinousBlobsController+, this will return the +GelatinousBlob+ class.
21
21
  def mdl
22
22
  @hammock_cached_mdl ||= Object.const_get to_s.sub('Controller', '').classify
23
+ rescue
24
+ log "No such model '#{to_s.sub('Controller', '').classify}'."
25
+ nil
23
26
  end
24
27
  # The lowercase name of the model this controller operates on. For example, for +GelatinousBlobsController+, this will return "gelatinous_blob".
25
28
  def mdl_name
data/lib/hammock.rb CHANGED
@@ -4,7 +4,7 @@ require 'ambition'
4
4
  require 'ambition/adapters/active_record'
5
5
 
6
6
  module Hammock
7
- VERSION = '0.2.23'
7
+ VERSION = '0.2.24'
8
8
 
9
9
  def self.included base # :nodoc:
10
10
  puts "Loading Hammock from #{loaded_from_gem? ? 'gem' : 'plugin'}"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hammock
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.23
4
+ version: 0.2.24
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Hoskings
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-04 00:00:00 +10:00
12
+ date: 2009-05-05 00:00:00 +10:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency