rerails 2.3.5.3 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,10 @@
1
+ === 3.0.0 / 2010-09-30
2
+
3
+ * 1 enhancement
4
+
5
+ * Get rid of ReactionView, for now (the previous patches are in Rails!).
6
+
7
+
1
8
  === 2.3.5.3 / 2010-01-15
2
9
 
3
10
  * 1 bugfix
@@ -5,31 +5,6 @@ Reinforcing the Rails with assorted patches.
5
5
 
6
6
  == Features
7
7
 
8
- === ReactionView
9
-
10
- * Label tag helpers accept blocks
11
- ({Rails Lighthouse ticket}[https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/3645-let-label-helpers-accept-blocks]).
12
-
13
- <% label_tag do %>
14
- <%= check_box_tag "tos" %> Accept <%= link_to "Terms", "/tos" %>.
15
- <% end %>
16
-
17
-
18
-
19
- * HTML5 form helpers
20
- ({Rails Lighthouse ticket}[https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/3646-html5-form-field-helpers-email_field_tag-etc]).
21
-
22
- <% form_tag "user_search" do %>
23
- <%= search_field_tag "q", nil, :autosave => true %>
24
- <% end %>
25
-
26
- <% form_for @user do |f| %>
27
- <%= f.email_field :email %>
28
- <%= f.url_field :homepage %>
29
- <%= f.phone_field :phone %>
30
- <% end %>
31
-
32
-
33
8
  === ReactiveRecord
34
9
 
35
10
  * <tt>Array#first</tt> and <tt>Array#last</tt> functionality and
@@ -43,32 +18,32 @@ Reinforcing the Rails with assorted patches.
43
18
 
44
19
  == Install
45
20
 
21
+ These instructions are for the master branch, to be used with edge Rails. For
22
+ Rails 2.3, try: http://github.com/stephencelis/rerails/tree/2-3-stable
23
+
46
24
  As a gem:
47
25
 
48
- # config/environment.rb
49
- config.gem "rerails", :version => '~> 2.3.5'
26
+ # Gemfile
27
+ gem "rerails", "3.0.0"
50
28
 
51
- % [sudo] rake gems:install
29
+ % bundle
52
30
 
53
31
 
54
32
  As a plugin:
55
33
 
56
- % script/plugin install git://github.com/stephencelis/rerails.git \
57
- -r 'branch 2-3-stable'
34
+ % script/plugin install git://github.com/stephencelis/rerails.git
58
35
 
59
36
 
60
37
  == Development
61
38
 
62
39
  Setup (to run tests):
63
40
 
64
- % [sudo] gem install bundler
65
- % gem bundle
66
- % bin/rake
41
+ % bundle && rake
67
42
 
68
43
 
69
44
  == License
70
45
 
71
- Released under the same license as Ruby on Rails (The MIT License).
46
+ Released under the same license as Ruby on Rails (the MIT License).
72
47
 
73
48
  (c) 2009-2010 Stephen Celis, stephen@stephencelis.com.
74
49
 
@@ -1,70 +1,96 @@
1
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])))
2
+ module FinderMethods #:nodoc:
3
+ def first(*args)
4
+ options = args.extract_options!
5
+ if options.any?
6
+ apply_finder_options(options).first(*args)
7
+ else
8
+ find_first(*args)
18
9
  end
10
+ end
19
11
 
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])))
12
+ def last(*args)
13
+ options = args.extract_options!
14
+ if options.any?
15
+ apply_finder_options(options).last(*args)
16
+ else
17
+ find_last(*args)
34
18
  end
19
+ end
35
20
 
36
- private
37
- def find_initial(options)
38
- every = find_every(options.merge(:limit => options[:limit] || 1))
39
- options[:limit] ? every : every.first
21
+ private
22
+ def find_first(n = nil)
23
+ if loaded?
24
+ @records.first(n)
25
+ elsif n.nil?
26
+ @first ||= limit(1).to_a[0]
27
+ else
28
+ limit(n).to_a
40
29
  end
30
+ end
41
31
 
42
- def find_last_with_limit(options)
43
- last = find_last_without_limit(options)
44
- options[:limit] ? last.reverse : last
32
+ def find_last(n = nil)
33
+ if loaded?
34
+ @records.first(n)
35
+ elsif n.nil?
36
+ @last ||= reverse_order.limit(1).to_a[0]
37
+ else
38
+ reverse_order.limit(n).to_a.reverse
45
39
  end
46
- alias_method_chain :find_last, :limit
47
- end
40
+ end
48
41
  end
49
42
 
50
43
  module Associations #:nodoc:
51
44
  class AssociationCollection < AssociationProxy
52
- # Fetches the first n records (default: 1) using SQL if possible.
45
+ def find(*args)
46
+ options = args.extract_options!
47
+
48
+ # If using a custom finder_sql, scan the entire collection.
49
+ if @reflection.options[:finder_sql]
50
+ expects_array = args.first.kind_of?(Array)
51
+ ids = args.flatten.compact.uniq.map { |arg| arg.to_i }
52
+
53
+ if ids.size == 1
54
+ id = ids.first
55
+ record = load_target.detect { |r| id == r.id }
56
+ expects_array ? [ record ] : record
57
+ else
58
+ load_target.select { |r| ids.include?(r.id) }
59
+ end
60
+ else
61
+ merge_options_from_reflection!(options)
62
+ construct_find_options!(options)
63
+
64
+ find_scope = construct_scope[:find].slice(:conditions, :order)
65
+
66
+ with_scope(:find => find_scope) do
67
+ relation = @reflection.klass.send(:construct_finder_arel, options, @reflection.klass.send(:current_scoped_methods))
68
+
69
+ case args.first
70
+ when :first, :last
71
+ relation.send(*args)
72
+ when :all
73
+ records = relation.all
74
+ @reflection.options[:uniq] ? uniq(records) : records
75
+ else
76
+ relation.find(*args)
77
+ end
78
+ end
79
+ end
80
+ end
81
+
53
82
  def first(*args)
54
83
  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])))
84
+ find(:first, *args)
57
85
  else
58
86
  load_target unless loaded?
59
87
  @target.first(*args)
60
88
  end
61
89
  end
62
90
 
63
- # Fetches the last n records (default: 1) using SQL if possible.
64
91
  def last(*args)
65
92
  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])))
93
+ find(:last, *args)
68
94
  else
69
95
  load_target unless loaded?
70
96
  @target.last(*args)
@@ -73,7 +99,7 @@ module ActiveRecord #:nodoc:
73
99
 
74
100
  private
75
101
  def fetch_first_or_last_using_find?(args)
76
- !(loaded? || @owner.new_record? || @reflection.options[:finder_sql]) ||
102
+ args.first.kind_of?(Hash) || !(loaded? || @owner.new_record? || @reflection.options[:finder_sql]) ||
77
103
  @target.any? { |record| record.new_record? }
78
104
  end
79
105
  end
@@ -82,18 +108,28 @@ module ActiveRecord #:nodoc:
82
108
  module NamedScope #:nodoc:
83
109
  class Scope
84
110
  def first(*args)
85
- if @found
86
- proxy_found.first(*args)
111
+ if loaded? && !args.first.kind_of?(Hash)
112
+ to_a.first(*args)
87
113
  else
88
- super
114
+ options = args.extract_options!
115
+ if options.any?
116
+ apply_finder_options(options).first(*args)
117
+ else
118
+ super
119
+ end
89
120
  end
90
121
  end
91
122
 
92
123
  def last(*args)
93
- if @found
94
- proxy_found.last(*args)
124
+ if loaded? && !args.first.kind_of?(Hash)
125
+ to_a.last(*args)
95
126
  else
96
- super
127
+ options = args.extract_options!
128
+ if options.any?
129
+ apply_finder_options(options).last(*args)
130
+ else
131
+ super
132
+ end
97
133
  end
98
134
  end
99
135
  end
@@ -1,2 +1 @@
1
- require "reaction_view"
2
1
  require "reactive_record"
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rerails
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.5.3
4
+ prerelease: false
5
+ segments:
6
+ - 3
7
+ - 0
8
+ - 0
9
+ version: 3.0.0
5
10
  platform: ruby
6
11
  authors:
7
12
  - Stephen Celis
@@ -9,20 +14,25 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2010-01-15 00:00:00 -06:00
17
+ date: 2010-09-30 00:00:00 -05:00
13
18
  default_executable:
14
19
  dependencies:
15
20
  - !ruby/object:Gem::Dependency
16
21
  name: rails
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
20
25
  requirements:
21
- - - "="
26
+ - - ~>
22
27
  - !ruby/object:Gem::Version
23
- version: 2.3.5
24
- version:
25
- description: Assorted patches to make Rails a bit better.
28
+ segments:
29
+ - 3
30
+ - 0
31
+ - 0
32
+ version: 3.0.0
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ description: Assorted patches for Rails.
26
36
  email: stephen@stephencelis.com
27
37
  executables: []
28
38
 
@@ -34,9 +44,6 @@ extra_rdoc_files:
34
44
  files:
35
45
  - CHANGELOG.rdoc
36
46
  - README.rdoc
37
- - lib/reaction_view/block_labels.rb
38
- - lib/reaction_view/html5_forms.rb
39
- - lib/reaction_view.rb
40
47
  - lib/reactive_record/first_last_limits.rb
41
48
  - lib/reactive_record.rb
42
49
  - lib/rerails.rb
@@ -51,21 +58,25 @@ rdoc_options:
51
58
  require_paths:
52
59
  - lib
53
60
  required_ruby_version: !ruby/object:Gem::Requirement
61
+ none: false
54
62
  requirements:
55
63
  - - ">="
56
64
  - !ruby/object:Gem::Version
65
+ segments:
66
+ - 0
57
67
  version: "0"
58
- version:
59
68
  required_rubygems_version: !ruby/object:Gem::Requirement
69
+ none: false
60
70
  requirements:
61
71
  - - ">="
62
72
  - !ruby/object:Gem::Version
73
+ segments:
74
+ - 0
63
75
  version: "0"
64
- version:
65
76
  requirements: []
66
77
 
67
78
  rubyforge_project:
68
- rubygems_version: 1.3.5
79
+ rubygems_version: 1.3.7
69
80
  signing_key:
70
81
  specification_version: 3
71
82
  summary: Reinforcing the Rails
@@ -1,2 +0,0 @@
1
- require "reaction_view/block_labels"
2
- require "reaction_view/html5_forms"
@@ -1,66 +0,0 @@
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
@@ -1,163 +0,0 @@
1
- module ActionView #:nodoc:
2
- module Helpers #:nodoc:
3
- module FormTagHelper
4
- # Creates a search field.
5
- #
6
- # ==== Options
7
- # * <tt>:autosave</tt> - If set to true, will generate a domain-based
8
- # namespace (e.g., for blog.rubyonrails.com, "com.rubyonrails.blog").
9
- # Also accepts string values.
10
- # * <tt>:results</tt> - The number of previous searches displayed in the
11
- # drop-down. Default: 10, with <tt>:autosave</tt>.
12
- # * Otherwise accepts the same options as text_field_tag.
13
- #
14
- # ==== Examples
15
- # search_field_tag 'query'
16
- # # => <input id="query" name="query" type="search" />
17
- #
18
- # search_field_tag 'query', nil, :autosave => true
19
- # # => <input id="query" name="query" type="search" autosave="tld.yourdomain" results="10">
20
- #
21
- # search_field_tag 'site_search', nil, :autosave => 'com.rubyonrails', :results => 5
22
- # # => <input id="site_search" name="site_search" type="search" autosave="com.rubyonrails" results="5">
23
- def search_field_tag(name, value = nil, options = {})
24
- options = options.stringify_keys
25
-
26
- if options["autosave"]
27
- if options["autosave"] == true
28
- options["autosave"] = request.host.split(".").reverse.join(".")
29
- end
30
- options["results"] ||= 10
31
- end
32
-
33
- if options["onsearch"]
34
- options["incremental"] = true unless options.has_key?("incremental")
35
- end
36
-
37
- text_field_tag(name, value, options.update("type" => "search"))
38
- end
39
-
40
- # Creates a text field of type "tel".
41
- #
42
- # ==== Options
43
- # * Accepts the same options as text_field_tag.
44
- def telephone_field_tag(name, value = nil, options = {})
45
- text_field_tag(name, value, options.stringify_keys.update("type" => "tel"))
46
- end
47
- alias phone_field_tag telephone_field_tag
48
-
49
- # Creates a text field of type "url".
50
- #
51
- # ==== Options
52
- # * Accepts the same options as text_field_tag.
53
- def url_field_tag(name, value = nil, options = {})
54
- text_field_tag(name, value, options.stringify_keys.update("type" => "url"))
55
- end
56
-
57
- # Creates a text field of type "email".
58
- #
59
- # ==== Options
60
- # * Accepts the same options as text_field_tag.
61
- def email_field_tag(name, value = nil, options = {})
62
- text_field_tag(name, value, options.stringify_keys.update("type" => "email"))
63
- end
64
-
65
- # Creates a number field.
66
- #
67
- # ==== Options
68
- # * <tt>:min</tt> - The minimum acceptable value.
69
- # * <tt>:max</tt> - The maximum acceptable value.
70
- # * <tt>:in</tt> - A range specifying the <tt>:min</tt> and
71
- # <tt>:max</tt> values.
72
- # * <tt>:step</tt> - The acceptable value granularity.
73
- # * Otherwise accepts the same options as text_field_tag.
74
- #
75
- # ==== Examples
76
- # number_field_tag 'quantity', nil, :in => 1...10
77
- # => <input id="quantity" name="quantity" min="1" max="9" />
78
- def number_field_tag(name, value = nil, options = {})
79
- options = options.stringify_keys
80
- options["type"] ||= "number"
81
- if range = options.delete("in") || options.delete("within")
82
- options.update("min" => range.min, "max" => range.max)
83
- end
84
- text_field_tag(name, value, options)
85
- end
86
-
87
- # Creates a range form element.
88
- #
89
- # ==== Options
90
- # * Accepts the same options as number_field_tag.
91
- def range_field_tag(name, value = nil, options = {})
92
- number_field_tag(name, value, options.stringify_keys.update("type" => "range"))
93
- end
94
- end
95
-
96
- module FormHelper #:nodoc:
97
- def search_field(object_name, method, options = {})
98
- options = options.stringify_keys
99
-
100
- if options["autosave"]
101
- if options["autosave"] == true
102
- options["autosave"] = request.host.split(".").reverse.join(".")
103
- end
104
- options["results"] ||= 10
105
- end
106
-
107
- if options["onsearch"]
108
- options["incremental"] = true unless options.has_key?("incremental")
109
- end
110
-
111
- InstanceTag.new(object_name, method, self, options.delete(:object)).to_input_field_tag("search", options)
112
- end
113
-
114
- def telephone_field(object_name, method, options = {})
115
- InstanceTag.new(object_name, method, self, options.delete(:object)).to_input_field_tag("tel", options)
116
- end
117
- alias phone_field telephone_field
118
-
119
- def url_field(object_name, method, options = {})
120
- InstanceTag.new(object_name, method, self, options.delete(:object)).to_input_field_tag("url", options)
121
- end
122
-
123
- def email_field(object_name, method, options = {})
124
- InstanceTag.new(object_name, method, self, options.delete(:object)).to_input_field_tag("email", options)
125
- end
126
-
127
- def number_field(object_name, method, options = {})
128
- options = options.stringify_keys
129
- options["type"] ||= "number"
130
- if range = options.delete("in") || options.delete("within")
131
- options.update("min" => range.min, "max" => range.max)
132
- end
133
- InstanceTag.new(object_name, method, self, options.delete(:object)).to_input_field_tag("number", options)
134
- end
135
-
136
- def range_field(object_name, method, options = {})
137
- options = options.stringify_keys
138
- options["type"] ||= "range"
139
- if range = options.delete("in") || options.delete("within")
140
- options.update("min" => range.min, "max" => range.max)
141
- end
142
- InstanceTag.new(object_name, method, self, options.delete(:object)).to_input_field_tag("range", options)
143
- end
144
- end
145
-
146
- class FormBuilder #:nodoc:
147
- %w(search_field telephone_field url_field email_field number_field range_field).each do |selector|
148
- src = <<-end_src
149
- def #{selector}(method, options = {})
150
- @template.send(
151
- #{selector.inspect},
152
- @object_name,
153
- method,
154
- objectify_options(options))
155
- end
156
- end_src
157
- class_eval src, __FILE__, __LINE__
158
- end
159
-
160
- alias phone_field telephone_field
161
- end
162
- end
163
- end