Module: Interrogator

Defined in:
lib/interrogator.rb,
lib/interrogator/version.rb,
lib/interrogator/conditions.rb

Defined Under Namespace

Classes: Conditions

Constant Summary collapse

VERSION =
"1.0.0"

Instance Method Summary collapse

Instance Method Details

#associated_models_hashObject



27
28
29
30
31
32
33
34
35
36
# File 'lib/interrogator.rb', line 27

def associated_models_hash
   {}.tap do |hash|
    [:has_many, :has_one, :belongs_to].each do |assoc|
      hash[assoc] = []
      reflect_on_all_associations(assoc).each do |reflection|
        hash[assoc] << {:name => reflection.name, :options => reflection.options.tap{|o| o.delete(:extend)}}
      end
    end
  end
end

#simple_columns_array(options = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/interrogator.rb', line 8

def simple_columns_array(options={})
  @interrogator_columns_hash ||= columns_hash
  sort = options[:sort]||true
  excl_columns = options[:except]||[]
  incl_columns = options[:only]||[]
  res=[]
  @interrogator_columns_hash.each { |k, v|
    ks=k.to_sym
    next if excl_columns.include?(ks) || (!incl_columns.empty? && !incl_columns.include?(ks))
    res << {
      :column_name => k,
      :type => v.type,
      :limit => v.limit,
      :null => v.null
    }
  }
  sort ? res.sort{|a,b| a[:column_name] <=> b[:column_name]} : res
end