Module: ArIdeyabox
- Defined in:
- lib/ar_ideyabox.rb
Instance Method Summary collapse
- #by_position ⇒ Object
- #first_el_tryer(object, by) ⇒ Object
- #has_not_this(model_name, *args) ⇒ Object
-
#visible ⇒ Object
In model just add this line has_not_this :person, through: :professions_people, order: :title, by: :title, group_by: :title :order and :by - optionally :group_by is for group selectors, if you want grouping roles by play titles, just add group_by: :title.
- #visible_by_position ⇒ Object
Instance Method Details
#by_position ⇒ Object
11 12 13 |
# File 'lib/ar_ideyabox.rb', line 11 def by_position order(:position) end |
#first_el_tryer(object, by) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/ar_ideyabox.rb', line 19 def first_el_tryer(object, by) if by.class == Hash object.try(by.keys[0]).try(by.values[0]) else object.try(by) end end |
#has_not_this(model_name, *args) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/ar_ideyabox.rb', line 27 def has_not_this(model_name, *args) = args. join_model = [:through].to_s.singularize.camelize self_id_sym = "#{self.to_s.underscore}_id".to_sym array_first_el = [:by] ? [:by] : :title group_by = [:group_by] includes = [:includes] model_name_id = "#{model_name}_id" define_singleton_method("has_not_this_#{model_name}") do |ids| excluded_ids = join_model.constantize.where(model_name_id.to_sym => ids).collect(&self_id_sym) output = self.where{id << excluded_ids} output = output.includes(includes) if includes output = output.order([:order]) if [:order] if group_by output = output.group_by{|a| first_el_tryer(a, group_by)} output.delete(nil) output.each do |key, value| array = [] value.each do |el| array << [first_el_tryer(el, array_first_el), el.id] end output[key] = array end # output.to_a.sort else output.collect{|p| [first_el_tryer(p, array_first_el), p.id]} end end end |
#visible ⇒ Object
In model just add this line has_not_this :person, through: :professions_people, order: :title, by: :title, group_by: :title :order and :by - optionally :group_by is for group selectors, if you want grouping roles by play titles, just add group_by: :title
7 8 9 |
# File 'lib/ar_ideyabox.rb', line 7 def visible where(visible: true) end |
#visible_by_position ⇒ Object
15 16 17 |
# File 'lib/ar_ideyabox.rb', line 15 def visible_by_position visible.by_position end |