brendan-entrails 1.0.4 → 1.0.5

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.
@@ -1,12 +1,12 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = %q{entrails}
3
- s.version = "1.0.4"
3
+ s.version = "1.0.5"
4
4
 
5
5
  s.specification_version = 2 if s.respond_to? :specification_version=
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Brendan Baldwin"]
9
- s.date = "2008-08-26"
9
+ s.date = "2009-01-29"
10
10
  s.default_executable = %q{entrails}
11
11
  s.description = "This is a collection of extensions to Rails internals that I've found to be absolutely indispensible since I implimented them. The real action is happening in the following two files at the moment: http://github.com/brendan/entrails/tree/master/lib/entrails/active_record/better_conditions.rb http://github.com/brendan/entrails/tree/master/lib/entrails/active_record/find_by_association.rb"
12
12
  s.email = ["brendan@usergenic.com"]
@@ -1,3 +1,14 @@
1
+ # NamedRouteParameter is currently in the "hack" phase because its implementation
2
+ # essentially creates a duplicate route in memory for every named_route defined.
3
+ # The purpose of this hack is really to be able to determine which named_route is
4
+ # being recognized by simply tacking on a new parameter called :named_route.
5
+ #
6
+ # This can be helpful in shared partials where you may only want to display
7
+ # something for certain views and it would be nice to determine it from the
8
+ # named route. It is also very helpful if you need a concise standard name
9
+ # when analyzing the path from a local referer (indeed, this was the initial
10
+ # use case for its construction.)
11
+ #
1
12
  module Entrails::ActionController::NamedRouteParameter
2
13
 
3
14
  def add_named_route_with_named_route_parameter(name, path, options = {})
@@ -1,14 +1,46 @@
1
+ # TemplateForReferer, when included in ActionController::Base patches the built-in
2
+ # default_template_name method, which is used to determine what template to use in
3
+ # the app/views folder. It does this so that we can create special templates to
4
+ # respond to requests coming from specific named routes.
5
+ #
6
+ # Why? This can be useful when managing responses for requests coming to the same
7
+ # controller action from multiple contexts. This was created primarily to deal with
8
+ # context in an AJAX setting, where the javascript returned by an RJS file will
9
+ # depend on the current page in the browser, since you may be changing DOM structures
10
+ # specific to that page.
11
+ #
12
+ # Consider a social network site where you want to support giving users the ability
13
+ # to friend each other. You'll probably have a friendships resource which will respond
14
+ # to a post method, and you may want to support doing so via AJAX. Well in one case
15
+ # there may be an "add as friend" button on the user profile, which reacts by flipping
16
+ # the button to "remove friend". In another case you may have many buttons in a list
17
+ # which respond by redrawing the list and adding the new friend in another list.
18
+ #
19
+ # The solution provided by this module is to allow you to define templates based on
20
+ # the named_route from which the request is being issued/refered. So in the case of
21
+ # the button on the user profile, which would probably by the 'user' named route,
22
+ # you would define a create_for_user.js.rjs template to handle it in app/views/friendships.
23
+ # In the case of the list, say the users named route (i.e. the index of users),
24
+ # app/views/friendships/create_for_users.js.rjs
25
+ #
26
+ # If there is no specific template for the referer's named route or if the referer
27
+ # is not the local application, (determined by request.host) then we just revert to
28
+ # the default_template_name originally provided by Rails.
29
+ #
30
+ # Note that this behavior is not enabled just for rjs templates-- You can use it for
31
+ # any formats.
32
+ #
33
+ # Rails uses the controller and action names to determine the
34
+ # name of the template to load.
1
35
  module Entrails::ActionController::TemplateForReferer
2
36
 
3
37
  private
4
38
 
5
39
  def default_template_name_with_template_for_referer
6
40
  template_name = default_template_name_without_template_for_referer
7
- begin
8
- @template.pick_template("#{template_name}_for_#{referer_named_route}")
9
- rescue
10
- template_name
11
- end
41
+ template_name_for_referer = "#{template_name}_for_#{referer_named_route}"
42
+ return template_name_for_referer if template_exists?(template_name_for_referer)
43
+ template_name
12
44
  end
13
45
 
14
46
  def referer_host
@@ -39,4 +71,4 @@ module Entrails::ActionController::TemplateForReferer
39
71
  host.alias_method_chain :default_template_name, :template_for_referer
40
72
  end
41
73
 
42
- end
74
+ end
@@ -163,7 +163,7 @@ module Entrails::ActiveRecord::FindByAssociation
163
163
  match = /^find_or_(initialize|create)_by_([_a-zA-Z]\w*)$/.match(method_id.to_s) unless match
164
164
  if match
165
165
  action_type = ($1 =~ /by/) ? :finder : :instantiator
166
- attribute_names = extract_attribute_names_from_match(match)
166
+ attribute_names = $2.split(/_and_/)
167
167
  options_argument = (arguments.size > attribute_names.size) ? arguments.last : {}
168
168
  associations = {}
169
169
  index = 0
@@ -241,7 +241,7 @@ module Entrails::ActiveRecord::FindByAssociation
241
241
  # database engines. This hack has been shown to significantly benefit query times
242
242
  # for mysql and sqlite3. (has not yet been tested with other engines.)
243
243
  def use_derived_table_hack_for_subquery_optimization?
244
- true
244
+ false
245
245
  end
246
246
 
247
247
  def self.extended(host)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brendan-entrails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brendan Baldwin
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-08-26 00:00:00 -07:00
12
+ date: 2009-01-29 00:00:00 -08:00
13
13
  default_executable: entrails
14
14
  dependencies: []
15
15