Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use class attribute for datagrid_attributes

  • Loading branch information...
commit c38299eee3e3e15386f9ca506c73bc9b6967e9b5 1 parent 42df352
Bogdan Gusiev bogdan authored
Showing with 8 additions and 5 deletions.
  1. +8 −5 lib/datagrid/core.rb
13 lib/datagrid/core.rb
View
@@ -8,6 +8,8 @@ def self.included(base)
base.extend ClassMethods
base.class_eval do
class_attribute :scope_value
+ class_attribute :datagrid_attributes
+ self.datagrid_attributes = []
end
base.send :include, InstanceMethods
end # self.included
@@ -30,10 +32,6 @@ def datagrid_attribute(name, &block)
end
end
- def datagrid_attributes
- @datagrid_attributes ||= []
- end
-
def scope(&block)
if block
self.scope_value = block
@@ -53,6 +51,11 @@ def check_scope_defined!(message = nil)
raise(Datagrid::ConfigurationError, message) unless scope_value
end
+ def inherited(child_class)
+ super(child_class)
+ child_class.datagrid_attributes = self.datagrid_attributes.clone
+ end
+
end # ClassMethods
module InstanceMethods
@@ -67,7 +70,7 @@ def initialize(attributes = nil)
def attributes
result = {}
- self.class.datagrid_attributes.each do |name|
+ self.datagrid_attributes.each do |name|
result[name] = self[name]
end
result
Please sign in to comment.
Something went wrong with that request. Please try again.