lib/serially/serially.rb
# override this to provide a custom way of creating instances of your class
override this to provide a custom way of creating instances of your class
override this to provide a custom way of creating instances of your class
def create_instance(*args)
        instance = nil
        args = args.flatten
        if self.is_active_record?
          if args.count == 1
            instance = args[0].is_a?(Fixnum) ? self.where(id: args[0]).first : self.where(args[0]).first
            raise Serially::ArgumentError.new("Serially: couldn't create ActiveRecord instance with provided arguments: #{args[0]}") if instance.blank?
          else
            raise Serially::ArgumentError.new("Serially: default implementation of ::create_instance expects to receive either id or hash")
          end
        else
          begin
            instance = args.blank? ? new : new(*args)
          rescue StandardError => exc
            raise Serially::ArgumentError.new("Serially: since no implementation of ::create_instance is provided in #{self}, tried to call new, but failed with provided arguments: #{args}")
          end
        end
        instance
      end
def create_instance ( * args ) instance = nil args = args . flatten if self . is_active_record? if args . count == 1 instance = args [ 0 ] . is_a? ( Fixnum ) ? self . where ( id : args [ 0 ] ) . first : self . where ( args [ 0 ] ) . first raise Serially :: ArgumentError . new ( "Serially: couldn't create ActiveRecord instance with provided arguments: #{args[0]}" ) if instance . blank? else raise Serially :: ArgumentError . new ( "Serially: default implementation of ::create_instance expects to receive either id or hash" ) end else begin instance = args . blank? ? new : new ( * args ) rescue StandardError => exc raise Serially :: ArgumentError . new ( "Serially: since no implementation of ::create_instance is provided in #{self}, tried to call new, but failed with provided arguments: #{args}" ) end end instance end
override this to provide a custom way of creating instances of your class
override this to provide a custom way of creating instances of your class
args