Module: FacetFor
- Defined in:
- lib/facet_for.rb,
lib/facet_for/version.rb
Defined Under Namespace
Classes: Facet
Constant Summary collapse
- PREDICATES =
[ ['Contains', :cont], ['Doesn\'t Contain', :not_cont], ['Starts With', :start], ['Doesn\'t Start With', :not_start], ['Ends With', :end], ['Doesn\'t End With', :not_end], ['Between', :between], ['Is Null', :null], ['Is Not Null', :not_null], ['Collection', :collection], ['Is True', :true], ['Is False', :false] ]
- VERSION =
"0.1.6"
Class Method Summary collapse
- .column_options(q) ⇒ Object
-
.create_facet(*args) ⇒ Object
We can use reflections to determine has_many and belongs_to associations.
- .field_options(q) ⇒ Object
- .options_for_model(model, association = nil, grouped = false) ⇒ Object
- .predicates ⇒ Object
Class Method Details
.column_options(q) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/facet_for.rb', line 36 def self.(q) = [] .push([q.klass.to_s, (q.klass)]) q.context.searchable_associations.each do |association| association_model = association.camelcase.singularize.constantize .push([association_model.to_s, (association_model, association)]) end end |
.create_facet(*args) ⇒ Object
We can use reflections to determine has_many and belongs_to associations
28 29 30 31 32 33 |
# File 'lib/facet_for.rb', line 28 def self.create_facet(*args) = args. @facet = Facet.new() @facet.render_facet.html_safe end |
.field_options(q) ⇒ Object
49 50 51 52 53 |
# File 'lib/facet_for.rb', line 49 def self.(q) = (q.klass) | q.context.searchable_associations.map { |a| [a.titleize, a.to_sym] } end |
.options_for_model(model, association = nil, grouped = false) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/facet_for.rb', line 55 def self.(model, association = nil, grouped = false) = [] preface = '' if association # preface field names for cross model displaying preface = "#{association}." end if model.ransackable_attributes = model.ransackable_attributes.map { |a| [a.titleize, "#{preface}#{a}".to_sym] } end end |
.predicates ⇒ Object
22 23 24 |
# File 'lib/facet_for.rb', line 22 def self.predicates PREDICATES end |