Class: Edgar::Search

Inherits:
Object
  • Object
show all
Extended by:
ActiveModel::Conversion, ActiveModel::Naming, ActiveModel::Translation
Includes:
ActiveModel::Validations
Defined in:
app/models/edgar/search.rb

Overview

Search condition

Abstract class to SearchForm and SearchPopup to provide common method 'conditions'.

'Search' instance will be stored in vcontext.model.

@errors will be used for error_messages_for helper in search-form.

Direct Known Subclasses

SearchForm, SearchPopup

Defined Under Namespace

Classes: Cache

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Search) initialize(klass)

A new instance of Search



45
46
47
48
# File 'app/models/edgar/search.rb', line 45

def initialize(klass)
  @errors     = ActiveModel::Errors.new(self)
  @_klass_str = klass.to_s
end

Instance Attribute Details

- (Object) _klass_str

Returns the value of attribute _klass_str



43
44
45
# File 'app/models/edgar/search.rb', line 43

def _klass_str
  @_klass_str
end

- (Object) errors

Returns the value of attribute errors



43
44
45
# File 'app/models/edgar/search.rb', line 43

def errors
  @errors
end

Instance Method Details

- (Object) column_type(col_name) (private)

cache column type



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'app/models/edgar/search.rb', line 64

def column_type(col_name)
  cache = Cache.instance
  cache.klass_hash[@_klass_str] ||= {}
  if v = cache.klass_hash[@_klass_str][col_name.to_s]
    cache.hit += 1
    v
  else
    cache.miss += 1
    col = @_klass_str.constantize.columns.find{|c|
      c.name == col_name.to_s
    }
    if col
      cache.klass_hash[@_klass_str][col_name.to_s] = col.type
    end
  end
end

- (Object) conditions

generate search-conditions from ActiveRecord attributes

RETURN

[condition_string, value_array]

values for :conditions option on model



54
55
56
# File 'app/models/edgar/search.rb', line 54

def conditions
  raise "Not implemented"
end

- (Boolean) persisted?

Returns:

  • (Boolean)


58
59
60
# File 'app/models/edgar/search.rb', line 58

def persisted?
  false
end