select_extra_columns 0.0.1 → 0.0.2
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/CHANGELOG.markdown +5 -0
- data/lib/select_extra_columns.rb +22 -7
- metadata +3 -3
data/CHANGELOG.markdown
CHANGED
data/lib/select_extra_columns.rb
CHANGED
@@ -7,15 +7,16 @@ module SelectExtraColumns
|
|
7
7
|
module ClassMethods
|
8
8
|
def self.extended(active_record_class)
|
9
9
|
class << active_record_class
|
10
|
-
class_inheritable_array(:klasses_with_extra_columns)
|
11
10
|
alias_method_chain :find_every, :extra_columns
|
12
11
|
end
|
12
|
+
active_record_class.class_inheritable_array(:klasses_with_extra_columns)
|
13
|
+
active_record_class.klasses_with_extra_columns ||= []
|
13
14
|
end
|
14
15
|
|
15
16
|
def find_every_with_extra_columns options
|
16
17
|
extra_columns = options.delete(:extra_columns)
|
17
|
-
return
|
18
|
-
klass_with_extra_columns(extra_columns).find_every
|
18
|
+
return find_every_without_extra_columns options if extra_columns.empty?
|
19
|
+
klass_with_extra_columns(extra_columns).send(:find_every, options)
|
19
20
|
end
|
20
21
|
|
21
22
|
def validate_find_options(options)
|
@@ -27,19 +28,33 @@ module SelectExtraColumns
|
|
27
28
|
|
28
29
|
def klass_with_extra_columns extra_columns
|
29
30
|
# look for the class in the cache.
|
30
|
-
p "1.0"
|
31
31
|
self.klasses_with_extra_columns.select do | class_details |
|
32
32
|
return class_details[1] if class_details[0] == extra_columns
|
33
33
|
end
|
34
|
-
|
35
|
-
self.columns
|
34
|
+
# load the column definition
|
35
|
+
cols, cols_hash = self.columns, self.columns_hash
|
36
36
|
self.clone.tap do |klass|
|
37
|
+
prepare_extra_column_klass(klass, cols, cols_hash, extra_columns)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def prepare_extra_column_klass klass, cols, cols_hash, extra_columns
|
42
|
+
class << klass
|
43
|
+
attr_accessor :extra_columns
|
44
|
+
# over ride readonly_attributes to include the extra_columns
|
45
|
+
def readonly_attributes
|
46
|
+
(super || []) + self.extra_columns.keys(&:to_s)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
#Make new copy of @columns, and @columns_hash and @extra_columns variables
|
50
|
+
klass.instance_variable_set("@columns", cols.clone)
|
51
|
+
klass.instance_variable_set("@columns_hash", cols_hash.clone)
|
52
|
+
klass.extra_columns = extra_columns.clone
|
37
53
|
extra_columns.each do |col_name, col_type|
|
38
54
|
# add the new column to `columns` list and `columns_hash` hash.
|
39
55
|
klass.columns << (klass.columns_hash[col_name.to_s] = ActiveRecord::ConnectionAdapters::Column.new(col_name.to_s, nil, col_type.to_s))
|
40
56
|
end
|
41
57
|
self.klasses_with_extra_columns = [[extra_columns, klass]] # add the class to the cache
|
42
|
-
end
|
43
58
|
end
|
44
59
|
end
|
45
60
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 2
|
9
|
+
version: 0.0.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Kandada Boggu
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-03-
|
17
|
+
date: 2010-03-08 00:00:00 -08:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|