Class: Redistat::Finder

Inherits:
Object
  • Object
show all
Includes:
Database
Defined in:
lib/redistat/finder.rb,
lib/redistat/finder/date_set.rb

Defined Under Namespace

Classes: DateSet

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods included from Database

included

Constructor Details

- (Finder) initialize(opts = {})

A new instance of Finder



45
46
47
# File 'lib/redistat/finder.rb', line 45

def initialize(opts = {})
  set_options(opts)
end

Instance Attribute Details

- (Object) options (readonly)

Returns the value of attribute options



43
44
45
# File 'lib/redistat/finder.rb', line 43

def options
  @options ||= {}
end

Class Method Details

+ (Object) date



23
24
25
# File 'lib/redistat/finder.rb', line 23

def dates(from, till)
  new.dates(from, till)
end

+ (Object) dates(from, till)



20
21
22
# File 'lib/redistat/finder.rb', line 20

def dates(from, till)
  new.dates(from, till)
end

+ (Object) depth(unit)



34
35
36
# File 'lib/redistat/finder.rb', line 34

def depth(unit)
  new.depth(unit)
end

+ (Object) find(*args)



8
9
10
# File 'lib/redistat/finder.rb', line 8

def find(*args)
  new.find(*args)
end

+ (Object) from(date)



25
26
27
# File 'lib/redistat/finder.rb', line 25

def from(date)
  new.from(date)
end

+ (Object) interval(unit)



38
39
40
# File 'lib/redistat/finder.rb', line 38

def interval(unit)
  new.interval(unit)
end

+ (Object) label(label)



16
17
18
# File 'lib/redistat/finder.rb', line 16

def label(label)
  new.label(label)
end

+ (Object) scope(scope)



12
13
14
# File 'lib/redistat/finder.rb', line 12

def scope(scope)
  new.scope(scope)
end

+ (Object) till(date)



29
30
31
# File 'lib/redistat/finder.rb', line 29

def till(date)
  new.till(date)
end

+ (Object) untill



32
33
34
# File 'lib/redistat/finder.rb', line 32

def till(date)
  new.till(date)
end

Instance Method Details

- (Object) all(reload = false)



53
54
55
56
# File 'lib/redistat/finder.rb', line 53

def all(reload = false)
  @result = nil if reload
  @result ||= find
end

- (Object) children



78
79
80
81
82
# File 'lib/redistat/finder.rb', line 78

def children
  build_key.children.map { |key|
    self.class.new(options.merge(:label => key.label.to_s))
  }
end

- (Object) connection_ref(ref = nil)



84
85
86
87
88
89
# File 'lib/redistat/finder.rb', line 84

def connection_ref(ref = nil)
  return options[:connection_ref] if ref.nil?
  reset! if options[:connection_ref] != ref
  options[:connection_ref] = ref
  self
end

- (Object) dates(start, finish) Also known as: date



105
106
107
# File 'lib/redistat/finder.rb', line 105

def dates(start, finish)
  from(start).till(finish)
end

- (Object) depth(unit = nil)



125
126
127
128
129
130
# File 'lib/redistat/finder.rb', line 125

def depth(unit = nil)
  return options[:depth] if unit.nil?
  reset! if options[:depth] != unit
  options[:depth] = unit
  self
end

- (Object) each(&block)



62
63
64
# File 'lib/redistat/finder.rb', line 62

def each(&block)
  all.each(&block)
end

- (Object) each_with_index(&block)



70
71
72
# File 'lib/redistat/finder.rb', line 70

def each_with_index(&block)
  all.each_with_index(&block)
end

- (Object) find(opts = {})

Raises:



139
140
141
142
143
144
145
146
147
# File 'lib/redistat/finder.rb', line 139

def find(opts = {})
  set_options(opts)
  raise InvalidOptions.new if !valid_options?
  if options[:interval].nil? || !options[:interval]
    find_by_magic
  else
    find_by_interval
  end
end

- (Object) from(date = nil)



110
111
112
113
114
115
# File 'lib/redistat/finder.rb', line 110

def from(date = nil)
  return options[:from] if date.nil?
  reset! if options[:from] != date
  options[:from] = date
  self
end

- (Object) interval(unit = nil)



132
133
134
135
136
137
# File 'lib/redistat/finder.rb', line 132

def interval(unit = nil)
  return options[:interval] if unit.nil?
  reset! if options[:interval] != unit
  options[:interval] = unit
  self
end

- (Object) label(input = nil)



98
99
100
101
102
103
# File 'lib/redistat/finder.rb', line 98

def label(input = nil)
  return options[:label] if input.nil?
  reset! if options.has_key?(:label) && options[:label].to_s != input.to_s
  options[:label] = (!input.nil?) ? Label.new(input) : nil
  self
end

- (Object) map(&block)



66
67
68
# File 'lib/redistat/finder.rb', line 66

def map(&block)
  all.map(&block)
end

- (Object) parent



74
75
76
# File 'lib/redistat/finder.rb', line 74

def parent
  @parent ||= self.class.new(options.merge(:label => options[:label].parent)) unless options[:label].nil?
end

- (Object) scope(input = nil)



91
92
93
94
95
96
# File 'lib/redistat/finder.rb', line 91

def scope(input = nil)
  return options[:scope] if input.nil?
  reset! if !options[:scope].nil? && options[:scope].to_s != input.to_s
  options[:scope] = Scope.new(input)
  self
end

- (Object) till(date = nil) Also known as: until



117
118
119
120
121
122
# File 'lib/redistat/finder.rb', line 117

def till(date = nil)
  return options[:till] if date.nil?
  reset! if options[:till] != date
  options[:till] = date
  self
end

- (Object) total



58
59
60
# File 'lib/redistat/finder.rb', line 58

def total
  all.total
end