lib/closure_tree/support.rb in closure_tree-4.0.0 vs lib/closure_tree/support.rb in closure_tree-4.0.1
- old
+ new
@@ -11,13 +11,11 @@
:parent_column_name => 'parent_id',
:dependent => :nullify, # or :destroy or :delete_all -- see the README
:name_column => 'name',
:with_advisory_lock => true
}.merge(options)
-
raise IllegalArgumentException, "name_column can't be 'path'" if options[:name_column] == 'path'
-
end
def connection
model_class.connection
end
@@ -99,42 +97,41 @@
def quote(field)
connection.quote(field)
end
+ def order_option?
+ !options[:order].nil?
+ end
+
def order_option
- options[:order]
+ options[:order].to_s
end
def with_order_option(options)
- order_option ? options.merge(:order => order_option) : options
+ order_option? ? options.merge(:order => order_option) : options
end
def scope_with_order(scope, additional_order_by = nil)
- if order_option
- scope.order(*([additional_order_by, order_option].compact))
- else
- scope
- end
+ order_option? ? scope.order(*([additional_order_by, order_option].compact)) : scope
end
def with_order_option(options)
- if order_option
+ if order_option?
options[:order] = [options[:order], order_option].compact.join(",")
end
options
end
def order_is_numeric?
# The table might not exist yet (in the case of ActiveRecord::Observer use, see issue 32)
- return false if order_option.nil? || !model_class.table_exists?
+ return false if !order_option? || !model_class.table_exists?
c = model_class.columns_hash[order_option]
c && c.type == :integer
end
def order_column
- o = order_option
- o.split(' ', 2).first if o
+ order_option.split(' ', 2).first if order_option?
end
def require_order_column
raise ":order value, '#{order_option}', isn't a column" if order_column.nil?
end