Module: Picky::Source

Extended by:
Helpers::Identification
Defined in:
lib/picky/source.rb

Class Method Summary collapse

Methods included from Helpers::Identification

identifier_for

Class Method Details

.from(thing, nil_ok, index_name = nil) ⇒ Object

Either a thing responding to #each or a block is fine.



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/picky/source.rb', line 8

def self.from thing, nil_ok, index_name = nil
  if thing.respond_to?(:each) || thing.respond_to?(:call)
    thing
  else
    return if nil_ok
      
    raise ArgumentError.new("The source \#{identifier_for(index_name)}should respond to either the method #each or\nit can be a lambda/block, returning such a source.\n")
  end
end