Class: Headcount::Configuration::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/headcount/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBase

Returns a new instance of Base.



28
29
30
31
# File 'lib/headcount/configuration.rb', line 28

def initialize
  @path       = 'db/headcount.json'
  @timestamp  = '%Y-%m-%d %H:%M:%S'
end

Instance Attribute Details

#pathObject

Returns the value of attribute path.



26
27
28
# File 'lib/headcount/configuration.rb', line 26

def path
  @path
end

#timestampObject

Returns the value of attribute timestamp.



26
27
28
# File 'lib/headcount/configuration.rb', line 26

def timestamp
  @timestamp
end

Instance Method Details

#count(*arguments, &block) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/headcount/configuration.rb', line 37

def count(*arguments, &block)
  if list_given?(*arguments)
    count_each(arguments.flatten)
  else
    query   = arguments[0]
    options = arguments[1] || {}
    
    if query.respond_to?(:count)
      key = options[:as] || Headcount::Support.key_for(query)

      # just ignore blocks for now
      # not really finding a need for nested declarations
      #if block_given?
      #  evaluate(&block)
      #end

      Headcount.register(key, query)
    else
      raise UnsupportedQuery, 'query does not respond to :count'
    end
  end
end

#evaluate(&block) ⇒ Object



33
34
35
# File 'lib/headcount/configuration.rb', line 33

def evaluate(&block)
  instance_exec(self, &block)
end