Class: Mite::TimeEntryGroup

Inherits:
Base
  • Object
show all
Defined in:
lib/mite/time_entry_group.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

all, first, inherited, last, undo_destroy, #undo_destroy

Instance Attribute Details

#time_entries_paramsObject

Returns the value of attribute time_entries_params.



4
5
6
# File 'lib/mite/time_entry_group.rb', line 4

def time_entries_params
  @time_entries_params
end

Class Method Details

.find_every(options = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/mite/time_entry_group.rb', line 7

def find_every(options={})
  return TimeEntry.all(options) if !options[:params] || !options[:params][:group_by]
  
  returning super(options) do |records|
    records.each do |record| 
      if record.attributes["time_entries_params"]
        record.time_entries_params = record.attributes.delete("time_entries_params").attributes.stringify_keys
      end
    end
  end
end

Instance Method Details

#time_entries(options = {}) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/mite/time_entry_group.rb', line 20

def time_entries(options={})
  return [] unless time_entries_params.is_a?(Hash)
  
  empty_result = false
  
  options[:params] ||= {}
  options[:params].stringify_keys!
  options[:params].merge!(time_entries_params) do |key, v1, v2|
    empty_result = (v1 != v2)
    v2
  end
  
  return [] if empty_result
  
  TimeEntry.all(options)
end