rerails 2.3.5.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc ADDED
@@ -0,0 +1,9 @@
1
+ === 2.3.5.1 / 2009-12-23
2
+
3
+ * 2 major enhancements
4
+
5
+ * Add Array#first and Array#last limit functionality to
6
+ ActiveRecord::Base.first and ActiveRecord::Base.last; optimize LIMIT SQL
7
+ for "first" and "last" in associations and named scopes.
8
+
9
+ * Let label helpers accept blocks.
data/README.rdoc ADDED
@@ -0,0 +1,74 @@
1
+ = Rerails
2
+
3
+ Reinforcing the Rails with assorted patches.
4
+
5
+
6
+ == Features
7
+
8
+ === ReactionView
9
+
10
+ * Label tag helpers accept blocks.
11
+
12
+ <% label_tag do %>
13
+ <%= check_box_tag "tos" %> Accept <%= link_to "Terms", "/tos" %>.
14
+ <% end %>
15
+
16
+
17
+ === ReactiveRecord
18
+
19
+ * <tt>Array#first</tt> and <tt>Array#last</tt> functionality and
20
+ optimizations for <tt>ActiveRecord::Base</tt>, association collections, and
21
+ named scopes.
22
+
23
+ AngryMan.first(2) # => [#<AngryMan id: 1>, #<AngryMan id: 2>]
24
+ AngryMan.last(2) # => [#<AngryMan id: 11>, #<AngryMan id: 12>]
25
+
26
+
27
+ == Install
28
+
29
+ As a gem:
30
+
31
+ # config/environment.rb
32
+ config.gem "rerails", :version => '~> 2.3.5'
33
+
34
+ % [sudo] rake gems:install
35
+
36
+
37
+ As a plugin:
38
+
39
+ % script/plugin install git://github.com/stephencelis/rerails.git \
40
+ -r 'branch 2-3-stable'
41
+
42
+
43
+ == Development
44
+
45
+ Setup (to run tests):
46
+
47
+ [sudo] gem install bundler
48
+ gem bundle
49
+ bin/rake
50
+
51
+
52
+ == License
53
+
54
+ Released under the same license as Ruby on Rails (The MIT License).
55
+
56
+ (c) 2009 Stephen Celis, stephen@stephencelis.com.
57
+
58
+ Permission is hereby granted, free of charge, to any person obtaining a copy
59
+ of this software and associated documentation files (the "Software"), to deal
60
+ in the Software without restriction, including without limitation the rights
61
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
62
+ copies of the Software, and to permit persons to whom the Software is
63
+ furnished to do so, subject to the following conditions:
64
+
65
+ The above copyright notice and this permission notice shall be included in all
66
+ copies or substantial portions of the Software.
67
+
68
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
69
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
70
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
71
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
72
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
73
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
74
+ SOFTWARE.
@@ -0,0 +1,66 @@
1
+ module ActionView #:nodoc:
2
+ module Helpers #:nodoc:
3
+ module FormTagHelper
4
+ # Creates a label tag. Accepts a block.
5
+ #
6
+ # ==== Options
7
+ # * Creates standard HTML attributes for the tag.
8
+ #
9
+ # ==== Examples
10
+ # label_tag 'name'
11
+ # # => <label for="name">Name</label>
12
+ #
13
+ # label_tag 'name', 'Your name'
14
+ # # => <label for="name">Your Name</label>
15
+ #
16
+ # label_tag 'name', nil, :class => 'small_label'
17
+ # # => <label for="name" class="small_label">Name</label>
18
+ #
19
+ # label_tag do
20
+ # '<input type="checkbox" /> Accept <a>TOS</a>'
21
+ # end
22
+ # # => <label><input type="checkbox" /> Accept <a>TOS</a></label>
23
+ def label_tag_with_block(*args, &block)
24
+ if block_given?
25
+ options = args.extract_options!
26
+ options["for"] = name = args.shift
27
+ text = capture(&block)
28
+ concat label_tag_without_block(name, text, options)
29
+ else
30
+ label_tag_without_block(*args, &block)
31
+ end
32
+ end
33
+
34
+ alias_method_chain :label_tag, :block
35
+ end
36
+
37
+ module FormHelper #:nodoc:
38
+ def label_with_block(object_name, *args, &block)
39
+ if block_given?
40
+ options = args.extract_options!
41
+ method = args.shift
42
+ text = capture(&block)
43
+ concat label_without_block(object_name, method, text, options)
44
+ else
45
+ label_without_block(object_name, *args, &block)
46
+ end
47
+ end
48
+
49
+ alias_method_chain :label, :block
50
+ end
51
+
52
+ class FormBuilder #:nodoc:
53
+ def label_with_block(method, *args, &block)
54
+ if block_given?
55
+ options = args.extract_options!
56
+ text = @template.capture(&block)
57
+ @template.concat label_without_block(method, text, options)
58
+ else
59
+ label_without_block(method, *args)
60
+ end
61
+ end
62
+
63
+ alias_method_chain :label, :block
64
+ end
65
+ end
66
+ end
@@ -0,0 +1 @@
1
+ require "reaction_view/block_labels"
@@ -0,0 +1,101 @@
1
+ module ActiveRecord #:nodoc:
2
+ class Base
3
+ class << self
4
+ # A convenience wrapper for <tt>find(:first, *args)</tt>. You can pass in
5
+ # all the same arguments to this method as you can to
6
+ # <tt>find(:first)</tt>. The limit can be passed in directly as the
7
+ # first argument.
8
+ #
9
+ # ==== Examples
10
+ #
11
+ # Post.first
12
+ # # => #<Post id: 1, posted: false>
13
+ # Post.first(2, :conditions => { :posted => true })
14
+ # # => [#<Post id: 2, posted: true>, #<Post id: 3, posted: true>]
15
+ def first(*args)
16
+ options, limit = args.extract_options!, args.shift
17
+ find(:first, *(args << options.merge(:limit => limit || options[:limit])))
18
+ end
19
+
20
+ # A convenience wrapper for <tt>find(:last, *args)</tt>. You can pass in
21
+ # all the same arguments to this method as you can to
22
+ # <tt>find(:last)</tt>. The limit can be passed in directly as the
23
+ # first argument.
24
+ #
25
+ # ==== Examples
26
+ #
27
+ # Post.last
28
+ # # => #<Post id: 50, posted: false>
29
+ # Post.last(2, :conditions => { :posted => true })
30
+ # # => [#<Post id: 48, posted: true>, #<Post id: 49, posted: true>]
31
+ def last(*args)
32
+ options, limit = args.extract_options!, args.shift
33
+ find(:last, *(args << options.merge(:limit => limit || options[:limit])))
34
+ end
35
+
36
+ private
37
+ def find_initial(options)
38
+ every = find_every(options.merge(:limit => options[:limit] || 1))
39
+ options[:limit] ? every : every.first
40
+ end
41
+
42
+ def find_last_with_limit(options)
43
+ last = find_last_without_limit(options)
44
+ options[:limit] ? last.reverse : last
45
+ end
46
+ alias_method_chain :find_last, :limit
47
+ end
48
+ end
49
+
50
+ module Associations #:nodoc:
51
+ class AssociationCollection < AssociationProxy
52
+ # Fetches the first n records (default: 1) using SQL if possible.
53
+ def first(*args)
54
+ if fetch_first_or_last_using_find?(args)
55
+ options, limit = args.extract_options!, args.shift
56
+ find(:first, *(args << options.merge(:limit => limit || options[:limit])))
57
+ else
58
+ load_target unless loaded?
59
+ @target.first(*args)
60
+ end
61
+ end
62
+
63
+ # Fetches the last n records (default: 1) using SQL if possible.
64
+ def last(*args)
65
+ if fetch_first_or_last_using_find?(args)
66
+ options, limit = args.extract_options!, args.shift
67
+ find(:last, *(args << options.merge(:limit => limit || options[:limit])))
68
+ else
69
+ load_target unless loaded?
70
+ @target.last(*args)
71
+ end
72
+ end
73
+
74
+ private
75
+ def fetch_first_or_last_using_find?(args)
76
+ !(loaded? || @owner.new_record? || @reflection.options[:finder_sql]) ||
77
+ @target.any? { |record| record.new_record? }
78
+ end
79
+ end
80
+ end
81
+
82
+ module NamedScope #:nodoc:
83
+ class Scope
84
+ def first(*args)
85
+ if @found
86
+ proxy_found.first(*args)
87
+ else
88
+ super
89
+ end
90
+ end
91
+
92
+ def last(*args)
93
+ if @found
94
+ proxy_found.last(*args)
95
+ else
96
+ super
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end
@@ -0,0 +1 @@
1
+ require "reactive_record/first_last_limits"
data/lib/rerails.rb ADDED
@@ -0,0 +1,2 @@
1
+ require "reaction_view"
2
+ require "reactive_record"
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rerails
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.3.5.1
5
+ platform: ruby
6
+ authors:
7
+ - Stephen Celis
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-12-23 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rails
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - "="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.3.5
24
+ version:
25
+ description: Assorted patches to make Rails a bit better.
26
+ email: stephen@stephencelis.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - CHANGELOG.rdoc
33
+ - README.rdoc
34
+ files:
35
+ - CHANGELOG.rdoc
36
+ - README.rdoc
37
+ - lib/reaction_view/block_labels.rb
38
+ - lib/reaction_view.rb
39
+ - lib/reactive_record/first_last_limits.rb
40
+ - lib/reactive_record.rb
41
+ - lib/rerails.rb
42
+ has_rdoc: true
43
+ homepage: http://github.com/stephencelis/rerails
44
+ licenses: []
45
+
46
+ post_install_message:
47
+ rdoc_options:
48
+ - --main
49
+ - README.rdoc
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ version:
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: "0"
63
+ version:
64
+ requirements: []
65
+
66
+ rubyforge_project: rerails
67
+ rubygems_version: 1.3.5
68
+ signing_key:
69
+ specification_version: 3
70
+ summary: Reinforcing the Rails
71
+ test_files: []
72
+