listalicious 0.3.0 → 0.3.1

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.3.1
data/lib/listalicious.rb CHANGED
@@ -43,6 +43,50 @@ module Listalicious #:nodoc:
43
43
 
44
44
  module ActiveRecordExtensions # :nodoc:
45
45
 
46
+ class OrderableConfiguration
47
+ def initialize(target)
48
+ @target = target
49
+ end
50
+
51
+ # Provide fields that are orderable in the configuration block.
52
+ #
53
+ # *Note*: If +only+ or +except+ aren't called from within the configuration block, all fields will be orderable.
54
+ #
55
+ # === Example
56
+ # only :last_name, :email_address
57
+ def only(*args)
58
+ @target.orderable_fields = args
59
+ end
60
+
61
+ # Provide fields that are not to be orderable, with the default list being all fields.
62
+ #
63
+ # *Note*: If +only+ or +except+ aren't called from within the configuration block, all fields will be orderable.
64
+ #
65
+ # === Example
66
+ # except :id, :password
67
+ def except(*args)
68
+ @target.orderable_fields - args
69
+ end
70
+
71
+ # Provide the default sort field, optionally a direction, and additional options.
72
+ #
73
+ # === Supported options
74
+ # [:stable]
75
+ # Will force appending the default sort to the end of all sort requests. Default is false.
76
+ #
77
+ # === Example
78
+ # default :first_name (direction defaults to :asc)
79
+ # default :first_name, :stable => true
80
+ # default :first_name, :desc, :stable => true
81
+ def default(*args)
82
+ options = args.extract_options!
83
+ field = args.shift
84
+ direction = args.shift || :asc
85
+
86
+ @target.default_order = {:field => field, :direction => direction, :options => options}
87
+ end
88
+ end
89
+
46
90
  # Makes a given model orderable for lists
47
91
  #
48
92
  # To specify that a model behaves according to the Listalicious order style call orderable_fields. The
@@ -73,7 +117,7 @@ module Listalicious #:nodoc:
73
117
  # make all columns orderable, incase only or except aren't called in the configuration block
74
118
  self.orderable_fields = column_names.map { |column_name| column_name.to_s }
75
119
 
76
- instance_eval(&config_block)
120
+ OrderableConfiguration.new(self).instance_eval(&config_block)
77
121
  self.orderable_fields.collect!{ |field| field.to_s }
78
122
 
79
123
  self.default_order ||= {:field => self.orderable_fields.first, :direction => :desc}
@@ -81,48 +125,10 @@ module Listalicious #:nodoc:
81
125
  attach_orderable_scopes
82
126
  end
83
127
 
84
- # Provide fields that are orderable in the configuration block.
85
- #
86
- # *Note*: If +only+ or +except+ aren't called from within the configuration block, all fields will be orderable.
87
- #
88
- # === Example
89
- # only :last_name, :email_address
90
- def only(*args)
91
- self.orderable_fields = args
92
- end
93
-
94
- # Provide fields that are not to be orderable, with the default list being all fields.
95
- #
96
- # *Note*: If +only+ or +except+ aren't called from within the configuration block, all fields will be orderable.
97
- #
98
- # === Example
99
- # * except :id, :password
100
- def except(*args)
101
- self.orderable_fields - args
102
- end
103
-
104
- # Provide the default sort field, optionally a direction, and additional options.
105
- #
106
- # === Supported options
107
- # [:stable]
108
- # Will force appending the default sort to the end of all sort requests. Default is false.
109
- #
110
- # === Example
111
- # default :first_name (direction defaults to :asc)
112
- # default :first_name, :stable => true
113
- # default :first_name, :desc, :stable => true
114
- def default(*args)
115
- options = args.extract_options!
116
- field = args.shift
117
- direction = args.shift || :asc
118
-
119
- self.default_order = {:field => field, :direction => direction, :options => options}
120
- end
121
-
122
128
  # Attaches the ordered_from named scope to the model requesting it. The named scope can be chained in the
123
129
  # controller by using:
124
130
  #
125
- # +Users.ordered_by(params).paginate :page => params[:page], :per_page => 2+
131
+ # +Users.ordered_from(params).paginate :page => params[:page], :per_page => 2+
126
132
  #
127
133
  # The params are expected to be in a specific style:
128
134
  #
data/listalicious.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{listalicious}
8
- s.version = "0.3.0"
8
+ s.version = "0.3.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jeremy Jackson"]
12
- s.date = %q{2010-03-02}
12
+ s.date = %q{2010-03-04}
13
13
  s.description = %q{Semantic listing; a semantic way to build datagrid structures in Rails.}
14
14
  s.email = %q{jejacks0n@gmail.com}
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: listalicious
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Jackson
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-03-02 00:00:00 -07:00
12
+ date: 2010-03-04 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency