Module: Hippo::Concerns::ExportJoinTables::ClassMethods

Defined in:
lib/hippo/concerns/export_join_tables.rb

Instance Method Summary collapse

Instance Method Details

#export_join_tables(*tables) ⇒ Object

Mark a joined table as safe to be included in a query Primarily used for joining a model to a view for access to summarized data



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/hippo/concerns/export_join_tables.rb', line 14

def export_join_tables( *tables )
    include ExportedLimitEvaluator
    self.exported_join_tables ||= []
    tables.flatten!
    options = tables.extract_options!
    tables.each do | join_name |
        self.exported_join_tables << {
            name: join_name,
            limit: options[:limit]
        }
    end

end

#has_exported_join_table?(name, user) ⇒ Boolean

Has the join been marked as safe?

Returns:

  • (Boolean)


29
30
31
32
33
34
# File 'lib/hippo/concerns/export_join_tables.rb', line 29

def has_exported_join_table?(name, user)
    return true if name == 'details' # "details" is reserved for views and is always allowed
    self.exported_join_tables && self.exported_join_tables.detect{ | join |
        join[:name] == name && evaluate_export_limit( user, :join, join[:name], join[:limit] )
    }
end