brendan-entrails 1.0.3 → 1.0.4

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,10 +1,12 @@
1
- bin
2
- bin/entrails
3
1
  entrails.gemspec
4
2
  History.txt
5
3
  init.rb
6
4
  lib
7
5
  lib/entrails
6
+ lib/entrails/action_controller
7
+ lib/entrails/action_controller/named_route_parameter.rb
8
+ lib/entrails/action_controller/template_for_referer.rb
9
+ lib/entrails/action_controller.rb
8
10
  lib/entrails/active_record
9
11
  lib/entrails/active_record/better_conditions.rb
10
12
  lib/entrails/active_record/find_by_association.rb
data/Rakefile CHANGED
@@ -24,7 +24,7 @@ namespace :gem do
24
24
  s.default_executable = %q{entrails}
25
25
  s.description = #{Entrails::DESCRIPTION.inspect}
26
26
  s.email = #{Entrails::EMAIL.inspect}
27
- s.executables = ["entrails"]
27
+ s.executables = []
28
28
  s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.txt"]
29
29
  s.files = #{Entrails::MANIFEST.inspect}
30
30
  s.has_rdoc = true
@@ -1,18 +1,18 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = %q{entrails}
3
- s.version = "1.0.3"
3
+ s.version = "1.0.4"
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-06-21"
9
+ s.date = "2008-08-26"
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"]
13
- s.executables = ["entrails"]
13
+ s.executables = []
14
14
  s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.txt"]
15
- s.files = ["bin", "bin/entrails", "entrails.gemspec", "History.txt", "init.rb", "lib", "lib/entrails", "lib/entrails/active_record", "lib/entrails/active_record/better_conditions.rb", "lib/entrails/active_record/find_by_association.rb", "lib/entrails/active_record.rb", "lib/entrails.rb", "Manifest.txt", "Rakefile", "README.txt", "spec", "spec/entrails", "spec/entrails/active_record", "spec/entrails/active_record/better_conditions_spec.rb", "spec/entrails/active_record/find_by_association_spec.rb", "spec/spec_helper.rb"]
15
+ s.files = ["entrails.gemspec", "History.txt", "init.rb", "lib", "lib/entrails", "lib/entrails/action_controller", "lib/entrails/action_controller/named_route_parameter.rb", "lib/entrails/action_controller/template_for_referer.rb", "lib/entrails/action_controller.rb", "lib/entrails/active_record", "lib/entrails/active_record/better_conditions.rb", "lib/entrails/active_record/find_by_association.rb", "lib/entrails/active_record.rb", "lib/entrails.rb", "Manifest.txt", "Rakefile", "README.txt", "spec", "spec/entrails", "spec/entrails/active_record", "spec/entrails/active_record/better_conditions_spec.rb", "spec/entrails/active_record/find_by_association_spec.rb", "spec/spec_helper.rb"]
16
16
  s.has_rdoc = true
17
17
  s.homepage = "http://github.com/brendan/entrails"
18
18
  s.rdoc_options = ["--main", "README.txt"]
data/init.rb CHANGED
@@ -1 +1,5 @@
1
- require 'entrails'
1
+ begin
2
+ require File.join(File.dirname(__FILE__), 'lib', 'entrails') # From here
3
+ rescue LoadError
4
+ require 'entrails' # From gem
5
+ end
@@ -1,5 +1,5 @@
1
1
  module Entrails
2
- VERSION='1.0.3'
2
+ VERSION='1.0.4'
3
3
  AUTHORS=["Brendan Baldwin"]
4
4
  EMAIL=["brendan@usergenic.com"]
5
5
  DESCRIPTION=%q{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}
@@ -8,9 +8,15 @@ module Entrails
8
8
  HOMEPAGE="http://github.com/brendan/entrails"
9
9
  end
10
10
 
11
+ require 'entrails/action_controller'
11
12
  require 'entrails/active_record'
12
13
 
13
- if defined?(ActiveRecord::Base)
14
+ if defined?(ActionController)
15
+ ActionController::Routing::RouteSet.send(:include, Entrails::ActionController::NamedRouteParameter)
16
+ ActionController::Base.send(:include, Entrails::ActionController::TemplateForReferer)
17
+ end
18
+
19
+ if defined?(ActiveRecord)
14
20
  ActiveRecord::Base.extend Entrails::ActiveRecord::BetterConditions
15
21
  ActiveRecord::Base.extend Entrails::ActiveRecord::FindByAssociation
16
22
  end
@@ -0,0 +1,5 @@
1
+ module Entrails::ActionController
2
+ end
3
+
4
+ require 'entrails/action_controller/named_route_parameter'
5
+ require 'entrails/action_controller/template_for_referer'
@@ -0,0 +1,13 @@
1
+ module Entrails::ActionController::NamedRouteParameter
2
+
3
+ def add_named_route_with_named_route_parameter(name, path, options = {})
4
+ addition = add_named_route_without_named_route_parameter(name, path, options.merge(:named_route => name.to_s))
5
+ add_route(path, options) # hack to allow generation from params that don't contain :named_route
6
+ addition
7
+ end
8
+
9
+ def self.included(host)
10
+ host.alias_method_chain :add_named_route, :named_route_parameter
11
+ end
12
+
13
+ end
@@ -0,0 +1,42 @@
1
+ module Entrails::ActionController::TemplateForReferer
2
+
3
+ private
4
+
5
+ def default_template_name_with_template_for_referer
6
+ 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
12
+ end
13
+
14
+ def referer_host
15
+ URI.parse(request.referer).host unless request.referer.blank?
16
+ end
17
+
18
+ def referer_host_local?
19
+ referer_host == request.host
20
+ end
21
+
22
+ def referer_named_route
23
+ referer_params[:named_route]
24
+ rescue
25
+ nil
26
+ end
27
+
28
+ def referer_params
29
+ (ActionController::Routing::Routes.recognize_path(referer_path, :method => :get) if referer_host_local?) || {}
30
+ rescue
31
+ {}
32
+ end
33
+
34
+ def referer_path
35
+ URI.parse(request.referer).path unless request.referer.blank?
36
+ end
37
+
38
+ def self.included(host)
39
+ host.alias_method_chain :default_template_name, :template_for_referer
40
+ end
41
+
42
+ end
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.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brendan Baldwin
@@ -9,15 +9,15 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-06-21 00:00:00 -07:00
12
+ date: 2008-08-26 00:00:00 -07:00
13
13
  default_executable: entrails
14
14
  dependencies: []
15
15
 
16
16
  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"
17
17
  email:
18
18
  - brendan@usergenic.com
19
- executables:
20
- - entrails
19
+ executables: []
20
+
21
21
  extensions: []
22
22
 
23
23
  extra_rdoc_files:
@@ -25,13 +25,15 @@ extra_rdoc_files:
25
25
  - Manifest.txt
26
26
  - README.txt
27
27
  files:
28
- - bin
29
- - bin/entrails
30
28
  - entrails.gemspec
31
29
  - History.txt
32
30
  - init.rb
33
31
  - lib
34
32
  - lib/entrails
33
+ - lib/entrails/action_controller
34
+ - lib/entrails/action_controller/named_route_parameter.rb
35
+ - lib/entrails/action_controller/template_for_referer.rb
36
+ - lib/entrails/action_controller.rb
35
37
  - lib/entrails/active_record
36
38
  - lib/entrails/active_record/better_conditions.rb
37
39
  - lib/entrails/active_record/find_by_association.rb
@@ -69,7 +71,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
69
71
  requirements: []
70
72
 
71
73
  rubyforge_project:
72
- rubygems_version: 1.0.1
74
+ rubygems_version: 1.2.0
73
75
  signing_key:
74
76
  specification_version: 2
75
77
  summary: "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"
File without changes