Class: Amiba::Source::FinderProxy

Inherits:
Object
  • Object
show all
Includes:
Repo, Enumerable
Defined in:
lib/amiba/source/entry_finder.rb

Instance Method Summary collapse

Methods included from Repo

#add_and_commit, #init, #last_commit_date, #last_commit_dates, #pull, #push, #repo

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



67
68
69
70
71
72
73
74
75
# File 'lib/amiba/source/entry_finder.rb', line 67

def method_missing(method_name, *args, &block)
  entry_types = (Dir.glob('entries/*') << "all").map {|c| File.basename(c).to_sym}
  if entry_types.include?(method_name)
    self[:category] = CategoryScope.new(method_name)
  else
    raise ArgumentError
  end
  self
end

Instance Method Details

#[](index) ⇒ Object



36
37
38
# File 'lib/amiba/source/entry_finder.rb', line 36

def [](index)
  entries[index]
end

#allObject



44
45
46
# File 'lib/amiba/source/entry_finder.rb', line 44

def all
  entries
end

#countObject



32
33
34
# File 'lib/amiba/source/entry_finder.rb', line 32

def count
  entries.count
end

#each(&blk) ⇒ Object



20
21
22
# File 'lib/amiba/source/entry_finder.rb', line 20

def each(&blk)
  entries.each(&blk)
end

#empty?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/amiba/source/entry_finder.rb', line 40

def empty?
  entries.empty?
end

#entriesObject



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/amiba/source/entry_finder.rb', line 48

def entries
  result = (scopes[:category] || CategoryScope.new).apply
  result = (scopes[:state] || StateScope.new).apply(result)
  # reverse sorting is a more natural approach
  result.sort! do |a, b|
    last_commit_date(b.filename) <=> last_commit_date(a.filename)
  end
  result = scopes[:offset].apply(result) if scopes[:offset]
  result = scopes[:limit].apply(result) if scopes[:limit]
  result
end

#firstObject



24
25
26
# File 'lib/amiba/source/entry_finder.rb', line 24

def first
  entries.first
end

#lastObject



28
29
30
# File 'lib/amiba/source/entry_finder.rb', line 28

def last
  entries.last
end

#limit(count) ⇒ Object



82
83
84
85
# File 'lib/amiba/source/entry_finder.rb', line 82

def limit(count)
  self[:limit] = LimitScope.new(count)
  self
end

#offset(index) ⇒ Object



77
78
79
80
# File 'lib/amiba/source/entry_finder.rb', line 77

def offset(index)
  self[:offset] = OffsetScope.new(index)
  self
end