2013-07-02 08:46:44 +00:00
|
|
|
module OrbitModel
|
|
|
|
|
|
|
|
module Status
|
|
|
|
|
|
|
|
def self.included(base)
|
|
|
|
base.extend ClassMethods
|
|
|
|
base.class_eval do
|
|
|
|
field :is_top, :type => Boolean, :default => false
|
|
|
|
field :is_hot, :type => Boolean, :default => false
|
|
|
|
field :is_hidden, :type => Boolean, :default => false
|
2013-10-16 18:18:32 +00:00
|
|
|
query = {type: 'where', conditions: {is_hidden: false}}
|
|
|
|
if class_variable_defined?(:@@can_display)
|
|
|
|
class_variable_set(:@@can_display, (class_variable_get(:@@can_display) << query))
|
|
|
|
else
|
|
|
|
class_variable_set(:@@can_display, [query])
|
|
|
|
end
|
2013-07-02 08:46:44 +00:00
|
|
|
send :include, InstanceMethods
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
module InstanceMethods
|
|
|
|
|
|
|
|
def is_top?
|
|
|
|
self.is_top
|
|
|
|
end
|
|
|
|
|
|
|
|
def is_hot?
|
|
|
|
self.is_hot
|
|
|
|
end
|
|
|
|
|
|
|
|
def is_hidden?
|
|
|
|
self.is_hidden
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
module ClassMethods
|
|
|
|
|
|
|
|
define_method(:can_display) do
|
2013-10-16 18:18:32 +00:00
|
|
|
final_query = class_variable_get(:@@can_display).inject('') do |result, query_hash|
|
|
|
|
result << "." if result.present?
|
|
|
|
result << "#{query_hash[:type]}(#{query_hash[:conditions]})"
|
|
|
|
result
|
|
|
|
end
|
|
|
|
eval(final_query)
|
2013-07-02 08:46:44 +00:00
|
|
|
end unless method_defined? :can_display
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|