Class: Redistat::Finder
- Inherits:
-
Object
- Object
- Redistat::Finder
- Includes:
- Database
- Defined in:
- lib/redistat/finder.rb,
lib/redistat/finder/date_set.rb
Defined Under Namespace
Classes: DateSet
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
- .date ⇒ Object
- .dates(from, till) ⇒ Object
- .depth(unit) ⇒ Object
- .find(*args) ⇒ Object
- .from(date) ⇒ Object
- .interval(unit) ⇒ Object
- .label(label) ⇒ Object
- .scope(scope) ⇒ Object
- .till(date) ⇒ Object
- .untill ⇒ Object
Instance Method Summary collapse
- #all(reload = false) ⇒ Object
- #children ⇒ Object
- #connection_ref(ref = nil) ⇒ Object
- #dates(start, finish) ⇒ Object (also: #date)
- #depth(unit = nil) ⇒ Object
- #each(&block) ⇒ Object
- #each_with_index(&block) ⇒ Object
- #find(opts = {}) ⇒ Object
- #from(date = nil) ⇒ Object
-
#initialize(opts = {}) ⇒ Finder
constructor
A new instance of Finder.
- #interval(unit = nil) ⇒ Object
- #label(input = nil) ⇒ Object
- #map(&block) ⇒ Object
- #parent ⇒ Object
- #scope(input = nil) ⇒ Object
- #till(date = nil) ⇒ Object (also: #until)
- #total ⇒ Object
Methods included from Database
Constructor Details
#initialize(opts = {}) ⇒ Finder
Returns a new instance of Finder.
45 46 47 |
# File 'lib/redistat/finder.rb', line 45 def initialize(opts = {}) (opts) end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
43 44 45 |
# File 'lib/redistat/finder.rb', line 43 def @options end |
Class Method Details
.date ⇒ Object
23 24 25 |
# File 'lib/redistat/finder.rb', line 23 def dates(from, till) new.dates(from, till) end |
.dates(from, till) ⇒ Object
20 21 22 |
# File 'lib/redistat/finder.rb', line 20 def dates(from, till) new.dates(from, till) end |
.depth(unit) ⇒ Object
34 35 36 |
# File 'lib/redistat/finder.rb', line 34 def depth(unit) new.depth(unit) end |
.find(*args) ⇒ Object
8 9 10 |
# File 'lib/redistat/finder.rb', line 8 def find(*args) new.find(*args) end |
.from(date) ⇒ Object
25 26 27 |
# File 'lib/redistat/finder.rb', line 25 def from(date) new.from(date) end |
.interval(unit) ⇒ Object
38 39 40 |
# File 'lib/redistat/finder.rb', line 38 def interval(unit) new.interval(unit) end |
.label(label) ⇒ Object
16 17 18 |
# File 'lib/redistat/finder.rb', line 16 def label(label) new.label(label) end |
.scope(scope) ⇒ Object
12 13 14 |
# File 'lib/redistat/finder.rb', line 12 def scope(scope) new.scope(scope) end |
.till(date) ⇒ Object
29 30 31 |
# File 'lib/redistat/finder.rb', line 29 def till(date) new.till(date) end |
.untill ⇒ Object
32 33 34 |
# File 'lib/redistat/finder.rb', line 32 def till(date) new.till(date) end |
Instance Method Details
#all(reload = false) ⇒ Object
53 54 55 56 |
# File 'lib/redistat/finder.rb', line 53 def all(reload = false) @result = nil if reload @result ||= find end |
#children ⇒ Object
78 79 80 81 82 |
# File 'lib/redistat/finder.rb', line 78 def children build_key.children.map { |key| self.class.new(.merge(:label => key.label.to_s)) } end |
#connection_ref(ref = nil) ⇒ Object
84 85 86 87 88 89 |
# File 'lib/redistat/finder.rb', line 84 def connection_ref(ref = nil) return [:connection_ref] if ref.nil? reset! if [:connection_ref] != ref [:connection_ref] = ref self end |
#dates(start, finish) ⇒ Object Also known as: date
105 106 107 |
# File 'lib/redistat/finder.rb', line 105 def dates(start, finish) from(start).till(finish) end |
#depth(unit = nil) ⇒ Object
125 126 127 128 129 130 |
# File 'lib/redistat/finder.rb', line 125 def depth(unit = nil) return [:depth] if unit.nil? reset! if [:depth] != unit [:depth] = unit self end |
#each(&block) ⇒ Object
62 63 64 |
# File 'lib/redistat/finder.rb', line 62 def each(&block) all.each(&block) end |
#each_with_index(&block) ⇒ Object
70 71 72 |
# File 'lib/redistat/finder.rb', line 70 def each_with_index(&block) all.each_with_index(&block) end |
#find(opts = {}) ⇒ Object
139 140 141 142 143 144 145 146 147 |
# File 'lib/redistat/finder.rb', line 139 def find(opts = {}) (opts) raise InvalidOptions.new if ! if [:interval].nil? || ![:interval] find_by_magic else find_by_interval end end |
#from(date = nil) ⇒ Object
110 111 112 113 114 115 |
# File 'lib/redistat/finder.rb', line 110 def from(date = nil) return [:from] if date.nil? reset! if [:from] != date [:from] = date self end |
#interval(unit = nil) ⇒ Object
132 133 134 135 136 137 |
# File 'lib/redistat/finder.rb', line 132 def interval(unit = nil) return [:interval] if unit.nil? reset! if [:interval] != unit [:interval] = unit self end |
#label(input = nil) ⇒ Object
98 99 100 101 102 103 |
# File 'lib/redistat/finder.rb', line 98 def label(input = nil) return [:label] if input.nil? reset! if .has_key?(:label) && [:label].to_s != input.to_s [:label] = (!input.nil?) ? Label.new(input) : nil self end |
#map(&block) ⇒ Object
66 67 68 |
# File 'lib/redistat/finder.rb', line 66 def map(&block) all.map(&block) end |
#parent ⇒ Object
74 75 76 |
# File 'lib/redistat/finder.rb', line 74 def parent @parent ||= self.class.new(.merge(:label => [:label].parent)) unless [:label].nil? end |
#scope(input = nil) ⇒ Object
91 92 93 94 95 96 |
# File 'lib/redistat/finder.rb', line 91 def scope(input = nil) return [:scope] if input.nil? reset! if ![:scope].nil? && [:scope].to_s != input.to_s [:scope] = Scope.new(input) self end |
#till(date = nil) ⇒ Object Also known as: until
117 118 119 120 121 122 |
# File 'lib/redistat/finder.rb', line 117 def till(date = nil) return [:till] if date.nil? reset! if [:till] != date [:till] = date self end |
#total ⇒ Object
58 59 60 |
# File 'lib/redistat/finder.rb', line 58 def total all.total end |