benhoskings-hammock 0.2.12 → 0.2.13

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/History.txt CHANGED
@@ -1,3 +1,14 @@
1
+ == 0.2.13 2009-04-07
2
+ Use update_attributes instead of adjust in #find_or_create_with.
3
+ Added optional statuses handling to #ajaxinate.
4
+ Moved semicolons from call to declaration of response_action in #ajaxinate.
5
+ Avoid specifying the request format as an empty string.
6
+
7
+
8
+ == 0.2.12.1 2009-04-01
9
+ Changed #log to #dlog for unmatched scope logging and related chatter.
10
+
11
+
1
12
  == 0.2.12 2009-03-31
2
13
  Added loading message.
3
14
  Moved require for hammock components within Hammock.included.
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.12"
5
+ s.version = "0.2.13"
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-03-31}
9
+ s.date = %q{2009-04-07}
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. Hammock enforces RESTful resource access by abstracting actions away from the controller in favour of a clean, model-like callback system. Hammock tackles the hard and soft sides of security at once with a scoping security system on your models. Specify who can verb what resources under what conditions once, and everything else - the actual security, link generation, index filtering - just happens. Hammock inspects your routes and resources to generate a routing tree for each resource. Parent resources in a nested route are handled transparently at every point - record retrieval, creation, and linking. It makes more sense when you see how it works though, so check out the screencast!}
11
11
  s.email = ["ben@hoskings.net"]
12
12
  s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.rdoc", "misc/scaffold.txt"]
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.12'
7
+ VERSION = '0.2.13'
8
8
 
9
9
  def self.included base # :nodoc:
10
10
  puts "Loading Hammock from #{loaded_from_gem? ? 'gem' : 'plugin'}"
@@ -37,7 +37,7 @@ module Hammock
37
37
  link_class = link_class_for route.verb, record, attribute
38
38
 
39
39
  link_params[:_method] = route.http_method
40
- link_params[:format] = opts[:format].to_s
40
+ link_params[:format] = opts[:format].to_s unless opts[:format].blank?
41
41
 
42
42
  form_elements_hash = if route.get?
43
43
  '{ }'
@@ -49,14 +49,21 @@ module Hammock
49
49
 
50
50
  response_action = case link_params[:format].to_s
51
51
  when 'js'
52
- "eval(response)"
52
+ "eval(response);"
53
53
  else
54
- "jQuery('.#{opts[:target] || link_class + '_target'}').before(response).remove()"
54
+ "jQuery('.#{opts[:target] || link_class + '_target'}').before(response).remove();"
55
55
  end
56
56
 
57
57
  # TODO check the response code in the callback, and replace :after with :success and :failure.
58
58
  js = %Q{
59
59
  jQuery('.#{link_class}').#{opts[:on] || 'click'}(function() {
60
+ var obj = null;
61
+
62
+ if (#{opts[:spinner] ? 'true' : 'false'}) {
63
+ obj = jQuery(this).parents('.#{record.base_model}:first').find('.statuses');
64
+ obj.find('.spinner').animate({opacity: 'show'}, 100);
65
+ }
66
+
60
67
  /*if (#{attribute.blank? ? 'false' : 'true'} && (jQuery('.#{link_class}_target .original_value').html() == jQuery('.#{link_class}_target .modify input').val())) {
61
68
  eval("#{clean_snippet opts[:skipped]}");
62
69
  } else*/ if (false == eval("#{clean_snippet opts[:before]}")) {
@@ -70,8 +77,14 @@ module Hammock
70
77
  #{link_params.to_flattened_json},
71
78
  #{forgery_key_json(route.http_method)}
72
79
  ),
73
- function(response) {
74
- #{response_action};
80
+ function(response, textStatus) {
81
+ #{response_action}
82
+ if ('success' == textStatus) {
83
+ if (obj) {
84
+ obj.children('.spinner').hide()
85
+ .siblings('.success').show().fadeOut(4000);
86
+ }
87
+ }
75
88
  eval("#{clean_snippet opts[:after]}");
76
89
  }
77
90
  );
@@ -89,7 +89,7 @@ module Hammock
89
89
  def find_or_create_with(find_attributes, create_attributes = {}, adjust_attributes = false)
90
90
  if record = find_or_new_with(find_attributes, create_attributes)
91
91
  log "Create failed. #{record.errors.inspect}", :skip => 1 if record.new_record? && !record.save
92
- log "Adjust failed. #{record.errors.inspect}", :skip => 1 if adjust_attributes && !record.adjust(create_attributes)
92
+ log "Adjust failed. #{record.errors.inspect}", :skip => 1 if adjust_attributes && !record.update_attributes(create_attributes)
93
93
  record
94
94
  end
95
95
  end
data/lib/hammock/scope.rb CHANGED
@@ -27,13 +27,13 @@ module Hammock
27
27
  raise "The verb at #{call_point} must be supplied as a Symbol." unless verb.nil? || verb.is_a?(Symbol)
28
28
  route = route_for verb, resource
29
29
  if route.safe? && !resource.indexable_by(current_user)
30
- log "#{requester_name} can't index #{resource.name.pluralize}. #{describe_call_point 4}"
30
+ dlog "#{requester_name} can't index #{resource.name.pluralize}. #{describe_call_point 4}"
31
31
  :not_found
32
32
  elsif !route.safe? && !make_createable(resource)
33
- log "#{requester_name} can't #{verb} #{resource.name.pluralize}. #{describe_call_point 4}"
33
+ dlog "#{requester_name} can't #{verb} #{resource.name.pluralize}. #{describe_call_point 4}"
34
34
  :read_only
35
35
  else
36
- # log "#{requester_name} can #{verb} #{resource.name.pluralize}."
36
+ # dlog "#{requester_name} can #{verb} #{resource.name.pluralize}."
37
37
  :ok
38
38
  end
39
39
  end
@@ -43,20 +43,20 @@ module Hammock
43
43
  route = route_for verb, record
44
44
  if route.verb.in?(:save, :create) && record.new_record?
45
45
  if !record.createable_by?(current_user)
46
- log "#{requester_name} can't create a #{record.class} with #{record.attributes.inspect}. #{describe_call_point 4}"
46
+ dlog "#{requester_name} can't create a #{record.class} with #{record.attributes.inspect}. #{describe_call_point 4}"
47
47
  :unauthed
48
48
  else
49
49
  :ok
50
50
  end
51
51
  else
52
52
  if !record.readable_by?(current_user)
53
- log "#{requester_name} can't see #{record.class}<#{record.id}>. #{describe_call_point 4}"
53
+ dlog "#{requester_name} can't see #{record.class}<#{record.id}>. #{describe_call_point 4}"
54
54
  :not_found
55
55
  elsif !route.safe? && !record.writeable_by?(current_user)
56
- log "#{requester_name} can't #{verb} #{record.class}<#{record.id}>. #{describe_call_point 4}"
56
+ dlog "#{requester_name} can't #{verb} #{record.class}<#{record.id}>. #{describe_call_point 4}"
57
57
  :read_only
58
58
  else
59
- # log "#{requester_name} can #{verb} #{record.class}<#{record.id}>."
59
+ # dlog "#{requester_name} can #{verb} #{record.class}<#{record.id}>."
60
60
  :ok
61
61
  end
62
62
  end
@@ -64,13 +64,13 @@ module Hammock
64
64
 
65
65
  def current_verb_scope
66
66
  if current_user && (scope_name = account_verb_scope?)
67
- # log "got an account_verb_scope #{scope_name}."
67
+ # dlog "got an account_verb_scope #{scope_name}."
68
68
  mdl.send scope_name, current_user
69
69
  elsif !(scope_name = public_verb_scope?)
70
70
  log "No #{current_user.nil? ? 'public' : 'account'} #{scope_name_for_action} scope available for #{mdl}.#{' May be available after login.' if account_verb_scope?}"
71
71
  nil
72
72
  else
73
- # log "got a #{scope_name} public_verb_scope."
73
+ # dlog "got a #{scope_name} public_verb_scope."
74
74
  mdl.send scope_name
75
75
  end
76
76
  end
@@ -84,15 +84,15 @@ module Hammock
84
84
  end
85
85
 
86
86
  def current_scope
87
- log "#{current_hammock_resource.mdl}, #{current_hammock_resource.ancestry.map(&:mdl).inspect}"
87
+ dlog "#{current_hammock_resource.mdl}, #{current_hammock_resource.ancestry.map(&:mdl).inspect}"
88
88
  if (verb_scope = current_verb_scope).nil?
89
89
  nil
90
90
  elsif (resultant_scope = verb_scope.within(current_nest_scope, current_hammock_resource.routing_parent)).nil?
91
91
  nil
92
92
  else
93
- # puts "nest: #{current_nest_scope.clauses.inspect}"
94
- # puts "verb: #{current_verb_scope.clauses.inspect}"
95
- puts "chained in (#{resultant_scope.owner}) current_scope: #{resultant_scope.clauses.inspect}"
93
+ # dlog "nest: #{current_nest_scope.clauses.inspect}"
94
+ # dlog "verb: #{current_verb_scope.clauses.inspect}"
95
+ dlog "chained in (#{resultant_scope.owner}) current_scope: #{resultant_scope.clauses.inspect}"
96
96
  resultant_scope = resultant_scope.chain(custom_scope) unless custom_scope.nil?
97
97
  resultant_scope.sort_by &mdl.sorter
98
98
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: benhoskings-hammock
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.12
4
+ version: 0.2.13
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-03-31 00:00:00 -07:00
12
+ date: 2009-04-07 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency